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

25
LINES

< > BotCompany Repo | #1024294 - mapToMap - map a list to a Map using a function returning a pair; also synonym of mapMapToMap

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

Libraryless. Click here for Pure Java version (2220L/14K).

1  
static Map mapLike mapToMap(O f, Iterable l) {
2  
  new Map map;
3  
  fOr (O o : l) {
4  
    Pair p = cast callF(f, o);
5  
    map.put(p.a, p.b);
6  
  }
7  
  ret map;
8  
}
9  
10  
static <A, B, C> Map<B, C> mapLike mapToMap(IF1<A, Pair<B, C>> f, Iterable<A> l) {
11  
  new Map<B, C> map;
12  
  fOr (A o : l) {
13  
    Pair<B, C> p = callF(f, o);
14  
    map.put(p.a, p.b);
15  
  }
16  
  ret map;
17  
}
18  
19  
static <A, B, C> Map<B, C> mapToMap(Iterable<A> l, IF1<A, Pair<B, C>> f) {
20  
  ret mapToMap(f, l);
21  
}
22  
23  
static <A, B, C, D> Map<C, D> mapToMap(IF2<A, B, Pair<C, D>> f, Map<A, B> m) {
24  
  ret mapMapToMap(f, m);
25  
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1024294
Snippet name: mapToMap - map a list to a Map using a function returning a pair; also synonym of mapMapToMap
Eternal ID of this version: #1024294/9
Text MD5: 017963a5549d2cd6a23ba5a16581b18b
Transpilation MD5: b21a280c6373b0bbde47d87f0ef7b9ff
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-10 17:32:12
Source code size: 576 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 48 / 90
Version history: 8 change(s)
Referenced in: [show references]

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