Skip to content

Add a couple of convinience methods to Map API #209

@ggleyzer

Description

@ggleyzer

When you need to convert a Map<K1, V1> into a Map<K2, V2>, there is an API for that - processAll, however it looks a bit inelegant:

Map<K1, V1> m1 = ...;
Map<K2, V2> m2 = m1.processAll(m1.keys, e1 -> makeE2(e1));

First, I need to explicitly pass m1.keys, secondly it always returns back a ListMap.

My suggestion is to add a couple of convenience methods:

  1. Same as current `processAll, but without the keys, operating on all keys:

     <Result> Map!<Key, Result> processAll(function Result(Entry) compute) {
         return processAll(keys, compute);
     }
    
  2. Same as current processAll, but taking either the resulting map or a builder of the resulting map (similar to collectors/aggregators in Collection.x) to allow the result to be of the specific flavor (e.g. HashMap). Alternatively, we could simply extend the existing processAll` method like this:

     <Result> Map!<Key, Result> processAll(Iterable<Key> keys,
                                           function Result(Entry) compute,
                                           Map!<Key, Result>?    result = Null)
    

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions