Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a couple of convinience methods to Map API #209

Open
ggleyzer opened this issue Apr 24, 2024 · 0 comments
Open

Add a couple of convinience methods to Map API #209

ggleyzer opened this issue Apr 24, 2024 · 0 comments
Assignees

Comments

@ggleyzer
Copy link
Collaborator

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)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants