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

11
LINES

< > BotCompany Repo | #1028140 // mapToKeys - iterate on list, keep object as value, function result as key

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

Libraryless. Click here for Pure Java version (4573L/25K).

static <A, B> Map<B, A> lambdaMapLike mapToKeys(Iterable<A> l, IF1<A, B> f) {
  if (l == null) null;
  new HashMap<B, A> map;
  for (A a : l)
    map.put(f.get(a), a);
  ret map;
}

static <A, B> Map<B, A> mapToKeys(IF1<A, B> f, Iterable<A> or A[] l) {
  ret mapToKeys(l, f);
}

Author comment

Began life as a copy of #1021879

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028140
Snippet name: mapToKeys - iterate on list, keep object as value, function result as key
Eternal ID of this version: #1028140/7
Text MD5: 56cd981dcdd3e3ec26855a61573ef70b
Transpilation MD5: fd8fc4ef0997c0df34cf9b9cf14232c4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-08 20:25:24
Source code size: 287 bytes / 11 lines
Pitched / IR pitched: No / No
Views / Downloads: 253 / 361
Version history: 6 change(s)
Referenced in: [show references]