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

28
LINES

< > BotCompany Repo | #1004239 // withoutNulls - drop null values from list, or null keys and null values from map

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

Libraryless. Click here for Pure Java version (137L/1K).

static <A> L<A> withoutNulls(Iterable<A> l) {
  if (l cast L)
    if (!containsNulls(l)) ret l;
  new L<A> l2;
  for (A a : l)
    if (a != null)
      l2.add(a);
  ret l2;
}

static <A, B> Map<A, B> withoutNulls(Map<A, B> map) {
  Map<A, B> map2 = similarEmptyMap(map);
  for (A a : keys(map))
    if (a != null) {
      B b = map.get(a);
      if (b != null)
        map2.put(a, b);
    }
  ret map2;
}

static <A> L<A> withoutNulls(A[] l) {
  new L<A> l2;
  if (l != null) for (A a : l)
    if (a != null)
      l2.add(a);
  ret l2;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004239
Snippet name: withoutNulls - drop null values from list, or null keys and null values from map
Eternal ID of this version: #1004239/10
Text MD5: 2a828f945b9a9113af504f45c77f41bb
Transpilation MD5: c6aacef92838a8f4dcb907035a2029d6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-05-28 15:21:59
Source code size: 564 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 532 / 615
Version history: 9 change(s)
Referenced in: [show references]