Libraryless. Click here for Pure Java version (5573L/30K).
1 | static Map mapKeys(O func, Map map) { |
2 | Map m = similarEmptyMap(map); // TODO: this might break when key type changes through func |
3 | for (O key : keys(map)) |
4 | m.put(callF(func, key), map.get(key)); |
5 | ret m; |
6 | } |
7 | |
8 | static Map mapKeys(Map map, O func) { |
9 | ret mapKeys(func, map); |
10 | } |
11 | |
12 | static <A, B, C> Map<B, C> mapKeys(Map<A, C> map, IF1<A, B> func) { |
13 | ret mapKeys(map, (O) func); |
14 | } |
15 | |
16 | static <A, B, C> Map<B, C> lambdaMapLike mapKeys(IF1<A, B> func, Map<A, C> map) { |
17 | ret mapKeys(map, func); |
18 | } |
19 | |
20 | ifclass MultiMap |
21 | static <A, B, C> MultiMap<B, C> mapKeys(IF1<A, C> f, MultiMap<A, B> mm) { |
22 | ret mapMultiMapKeys(f, mm); |
23 | } |
24 | endif |
25 | |
26 | ifclass MultiSetMap |
27 | static <A, B, C> MultiSetMap<B, C> mapKeys(IF1<A, C> f, MultiSetMap<A, B> mm) { |
28 | ret mapMultiSetMapKeys(f, mm); |
29 | } |
30 | endif |
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: | 534 / 735 |
Version history: | 6 change(s) |
Referenced in: | [show references] |