Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

48
LINES

< > BotCompany Repo | #1001913 - unnull

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (2481L) is out of date.

static String unnull(String s) {
  return s == null ? "" : s;
}

static <A> Collection<A> unnull(Collection<A> l) {
  ret l == null ? emptyList() : l;
}

static <A> L<A> unnull(L<A> l) { ret l == null ? emptyList() : l; }
static int[] unnull(int[] l) { ret l == null ? emptyIntArray() : l; }
static char[] unnull(char[] l) { ret l == null ? emptyCharArray() : l; }
static double[] unnull(double[] l) { ret l == null ? emptyDoubleArray() : l; }

static <A, B> Map<A, B> unnull(Map<A, B> l) {
  ret l == null ? emptyMap() : l;
}

static <A> Iterable<A> unnull(Iterable<A> i) {
  ret i == null ? emptyList() : i;
}

static <A> A[] unnull(A[] a) {
  ret a == null ? (A[]) emptyObjectArray() : a;
}

static BitSet unnull(BitSet b) {
  ret b == null ? new BitSet() : b;
}

ifclass Pt
static Pt unnull(Pt p) {
  ret p == null ? new Pt : p;
}
endif

//ifclass Symbol
ifndef SymbolAsString
static Symbol unnull(Symbol s) {
  ret s == null ? emptySymbol() : s;
}
//endif
endifndef

ifclass Pair
static <A, B> Pair<A, B> unnull(Pair<A, B> p) {
  ret p != null ? p : Pair(null, null);
}
endif

Author comment

Began life as a copy of #2000506

download  show line numbers  debug dex   

Travelled to 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jcllbfdqhrgy, lpdgvwnxivlt, mqqgnosmbjvj, omdjrrnzbjjv, onxytkatvevr, podlckwnjdmb, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, whxojlpjdney, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001913
Snippet name: unnull
Eternal ID of this version: #1001913/17
Text MD5: 28f221cd03d02f79097d60623e6ac749
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-12 02:53:43
Source code size: 1127 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 471 / 6890
Version history: 16 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1001913 & http://1001913.tinybrain.de