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

13
LINES

< > BotCompany Repo | #1025202 - mapMapToMap - map a Map to a similar type Map using a function taking two arguments and returning a pair

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

Libraryless. Click here for Pure Java version (2100L/14K).

static <A, B, C, D> Map<C, D> mapMapToMap(IF2<A, B, Pair<C, D>> f, Map<A, B> m) {
  if (m == null) null;
  Map<C, D> map = similarEmptyMap(m);
  for (Map.Entry<A, B> e : m.entrySet()) {
    Pair<C, D> p = f.get(e.getKey(), e.getValue());
    map.put(p.a, p.b);
  }
  ret map;
}

static <A, B, C, D> Map<C, D> mapMapToMap(Map<A, B> m, IF2<A, B, Pair<C, D>> f) {
  ret mapMapToMap(f, m);
}

Author comment

Began life as a copy of #1024294

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1025202
Snippet name: mapMapToMap - map a Map to a similar type Map using a function taking two arguments and returning a pair
Eternal ID of this version: #1025202/5
Text MD5: fbb21ed26808ded23f3487600ab714eb
Transpilation MD5: c4d2aff4314662623642f4712fbafd22
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-13 13:31:39
Source code size: 399 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 14 / 38
Version history: 4 change(s)
Referenced in: [show references]