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

30
LINES

< > BotCompany Repo | #1010892 // mapKeys - apply function to a map's keys

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

Libraryless. Click here for Pure Java version (5573L/30K).

static Map mapKeys(O func, Map map) {
  Map m = similarEmptyMap(map); // TODO: this might break when key type changes through func
  for (O key : keys(map))
    m.put(callF(func, key), map.get(key));
  ret m;
}

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

static <A, B, C> Map<B, C> mapKeys(Map<A, C> map, IF1<A, B> func) {
  ret mapKeys(map, (O) func);
}

static <A, B, C> Map<B, C> lambdaMapLike mapKeys(IF1<A, B> func, Map<A, C> map) {
  ret mapKeys(map, func);
}

ifclass MultiMap
static <A, B, C> MultiMap<B, C> mapKeys(IF1<A, C> f, MultiMap<A, B> mm) {
  ret mapMultiMapKeys(f, mm);
}
endif

ifclass MultiSetMap
static <A, B, C> MultiSetMap<B, C> mapKeys(IF1<A, C> f, MultiSetMap<A, B> mm) {
  ret mapMultiSetMapKeys(f, mm);
}
endif

Author comment

Began life as a copy of #1004652

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1010892
Snippet name: mapKeys - apply function to a map's keys
Eternal ID of this version: #1010892/7
Text MD5: 7091168f4081d8ac5876eafae1f2ccd7
Transpilation MD5: 7e75e2c214f82bbb6abb42fcc975eb05
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-11 05:32:56
Source code size: 790 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 533 / 734
Version history: 6 change(s)
Referenced in: [show references]