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

22
LINES

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

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

Libraryless. Click here for Pure Java version (2551L/16K).

static Map mapKeyAndFunction(Iterable l, O f) {
  ret mapKeyAndFunction(f, l);
}

static Map mapLike mapKeyAndFunction(O f, Iterable l) {
  new HashMap map;
  if (l != null) for (O o : l)
    map.put(o, callF(f, o));
  ret map;
}

static <A, B, C> Map<A, C> mapKeyAndFunction(Map<A, B> map, IF2<A, B, C> f) {
  new HashMap map2;
  if (map != null) for (A key, B value : map)
    map2.put(key, callF(f, key, value));
  ret map2;
}


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

Author comment

Began life as a copy of #1018013

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021879
Snippet name: mapKeyAndFunction - iterate on list, keep object as key, function result as value
Eternal ID of this version: #1021879/7
Text MD5: 97a40dfa8f6f18fce0fb9b8ea5b8b9ce
Transpilation MD5: a98b54c826122b189120f2262c69c2b0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-16 11:05:39
Source code size: 557 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 217 / 304
Version history: 6 change(s)
Referenced in: [show references]