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

66
LINES

< > BotCompany Repo | #1003239 - map - call function on list (takes function name, Runnable or function object with "get" method) / now also works on maps

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

Libraryless. Click here for Pure Java version (3126L/17K).

1  
static L map(Iterable l, O f) { ret map(f, l); }
2  
3  
static L map(O f, Iterable l) {
4  
  L x = emptyList(l);
5  
  if (l != null) for ping (O o : l)
6  
    x.add(callF(f, o));
7  
  ret x;
8  
}
9  
10  
ifclass F1
11  
  static <A, B> L<B> map(Iterable<A> l, F1<A, B> f) { ret map(f, l); }
12  
13  
  static <A, B> L<B> map(F1<A, B> f, Iterable<A> l) {
14  
    L x = emptyList(l);
15  
    if (l != null) for ping (A o : l)
16  
      x.add(callF(f, o));
17  
    ret x;
18  
  }
19  
endif
20  
21  
static <A, B> L<B> map(IF1<A, B> f, Iterable<A> l) { ret map(l, f); }
22  
static <A, B> L<B> map(Iterable<A> l, IF1<A, B> f) {
23  
  L x = emptyList(l);
24  
  if (l != null) for ping (A o : l)
25  
    x.add(f.get(o));
26  
  ret x;
27  
}
28  
  
29  
static <A, B> L<B> lambdaMapLike map(IF1<A, B> f, A[] l) { ret map(l, f); }
30  
static <A, B> L<B> map(A[] l, IF1<A, B> f) {
31  
  L x = emptyList(l);
32  
  if (l != null) for ping (A o : l)
33  
    x.add(f.get(o));
34  
  ret x;
35  
}
36  
  
37  
static L map(O f, O[] l) { ret map(f, asList(l)); }
38  
static L map(O[] l, O f) { ret map(f, l); }
39  
40  
static L map(O f, Map map) {
41  
  ret map(map, f);
42  
}
43  
44  
// map: func(key, value) -> list element
45  
static L map(Map map, O f) {
46  
  new L x;
47  
  if (map != null) for ping (O _e : map.entrySet()) {
48  
    Map.Entry e = (Map.Entry) _e;
49  
    x.add(callF(f, e.getKey(), e.getValue()));
50  
  }
51  
  ret x;
52  
}
53  
54  
static <A, B, C> L<C> map(Map<A, B> map, IF2<A, B, C> f) {
55  
  ret map(map, (O) f);
56  
}
57  
58  
// new magic alias for mapLL - does it conflict?
59  
60  
static <A, B> L<A> map(IF1<A, B> f, A data1, A... moreData) {
61  
  L x = emptyList(l(moreData)+1);
62  
  x.add(f.get(data1));
63  
  if (moreData != null) for ping (A o : moreData)
64  
    x.add(f.get(o));
65  
  ret x;
66  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 21 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jcllbfdqhrgy, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, snaazhdonpnp, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv

No comments. add comment

Snippet ID: #1003239
Snippet name: map - call function on list (takes function name, Runnable or function object with "get" method) / now also works on maps
Eternal ID of this version: #1003239/20
Text MD5: f22062cad267b78382cab0f81be5e7a9
Transpilation MD5: cf56e4d3e7e7b0392e60a792a320b12c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-14 07:50:20
Source code size: 1633 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 840 / 1049
Version history: 19 change(s)
Referenced in: [show references]