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

56
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 (1888L/12K).

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 (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 (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 (A o : l)
25  
    x.add(f.get(o));
26  
  ret x;
27  
}
28  
  
29  
static <A, B> L<B> 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 (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 (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  
}

download  show line numbers  debug dex   

Travelled to 16 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jcllbfdqhrgy, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, snaazhdonpnp, tslmcundralx, tvejysmllsmz, 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/17
Text MD5: ade73761de2be1e91aa10b5f848a68e4
Transpilation MD5: 809a3651a2f985635957c503bbf5e378
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-25 19:38:05
Source code size: 1332 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 586 / 637
Version history: 16 change(s)
Referenced in: [show references]

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