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

31
LINES

< > BotCompany Repo | #1004652 // mapValues - apply function to a map's values

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

Transpiled version (2765L) is out of date.

static Map mapValues(O func, Map map) {
  Map m = similarEmptyMap(map);
  for (O key : keys(map))
    m.put(key, callF(func, map.get(key)));
  ret m;
}

static <A, B, C> Map<A, C> mapValues(Map<A, B> map, IF1<B, C> f) {
  ret mapValues(f, map);
}

static <A, B, C> Map<A, C> lambdaMapLike mapValues(IF1<B, C> f, Map<A, B> map) {
  Map m = similarEmptyMap(map);
  for (A key, B val : map)
    m.put(key, f.get(val));
  ret m;
}

static Map mapValues(Map map, O func) {
  ret mapValues(func, map);
}

ifclass MultiMap
  static <A, B, C> MultiMap<A, C> mapValues(IF1<B, C> func, MultiMap<A, B> mm) {
    ret mapMultiMapValues(func, mm);
  }
  
  static <A, B, C> MultiMap<A, C> mapValues(MultiMap<A, B> mm, IF1<B, C> func) {
    ret mapValues(func, mm);
  }
endif

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1004652
Snippet name: mapValues - apply function to a map's values
Eternal ID of this version: #1004652/11
Text MD5: 0ab3cd919bc8f673dfb85184c854c3d4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-08 10:59:35
Source code size: 790 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 715 / 817
Version history: 10 change(s)
Referenced in: [show references]