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).

static Map mapLike mapToMap(O f, Iterable l) {
  new Map map;
  fOr (O o : l) {
    Pair p = cast callF(f, o);
    map.put(p.a, p.b);
  }
  ret map;
}

static <A, B, C> Map<B, C> mapLike mapToMap(IF1<A, Pair<B, C>> f, Iterable<A> l) {
  new Map<B, C> map;
  fOr (A o : l) {
    Pair<B, C> p = callF(f, o);
    map.put(p.a, p.b);
  }
  ret map;
}

static <A, B, C> Map<B, C> mapToMap(Iterable<A> l, IF1<A, Pair<B, C>> f) {
  ret mapToMap(f, l);
}

static <A, B, C, D> Map<C, D> mapToMap(IF2<A, B, Pair<C, D>> f, Map<A, B> m) {
  ret mapMapToMap(f, m);
}

download  show line numbers  debug dex   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pzhvpgtvlbxg, 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: 60 / 106
Version history: 8 change(s)
Referenced in: [show references]

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