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: 716 / 819
Version history: 10 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1010892 - mapKeys - apply function to a map's keys
#1013149 - valuesToString
#1020213 - mapMultiMapValues - apply function to a MultiMap's values
#1025495 - mapValuesToList
#1026745 - mapValues_nullOnNull - apply function to a map's values, return null if map is null
#1027783 - mapValues_pcall - apply function to a map's values
#1028172 - mapValuesToLinkedHashMap - apply function to a map's values
#1032735 - mapValues_withoutNulls - apply function to a map's values, drop null results