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

Provide addToMap method in Maps #718

Closed
gissuebot opened this issue Oct 31, 2014 · 5 comments
Closed

Provide addToMap method in Maps #718

gissuebot opened this issue Oct 31, 2014 · 5 comments

Comments

@gissuebot
Copy link

Original issue created by dancerjohn on 2011-09-22 at 12:09 PM


There are several new**Map methods in Maps. But it seems like you need a new method signature for each type of map. It would be helpful to have a method that takes a Map (therefore any Map implementation) and inserts key/value pairs into that map.

One possible signature would be:
   public <K, V> void addToMap(Map<K, V> map, Iterable<V> values, Function<V, K> keyFunction);

However, I would prefer a more generic version:
   public <I, K, V> void addToMap(Map<K, V> map, Iterable<I> inputs,
             Function<I, K> keyFunction, Function<I, V> valueFunction);

   public <I, K, V> void addToMap(Map<K, V> map, Iterable<I> inputs,
             Function<I, Entry<K, V>> entryFunction);

I have added implementations for Map & Multimap.

@gissuebot
Copy link
Author

Original comment posted by dancerjohn on 2011-09-22 at 12:11 PM


These signatures match those suggested in issue #679

#679

@gissuebot
Copy link
Author

Original comment posted by daniel.yokomizo on 2011-09-22 at 01:45 PM


I suggest naming it putAll to keep it consistent with Map.putAll and Iterables.addAll.

In my code I only have the putAll(Map<K,V>,Iterable<Map.Entry<K,V>>) version and other methods to make entries:

Function<E, Map.Entry<K,V>> newEntry(Function<E,K>,Function<E,V>)

The variant becomes just composition:

putAll(map,transform(iterable,newEntry(key,value)))

@gissuebot
Copy link
Author

Original comment posted by dancerjohn on 2011-09-22 at 02:28 PM


I had forgotten about putAll. I guess the case could be made that a combination of uniqueIndex and putAll would suffice. I still like the two function version though.

@gissuebot
Copy link
Author

Original comment posted by wasserman.louis on 2011-10-18 at 06:06 PM


Merging these into a single function would, I strongly believe, unacceptably compromise readability.


Status: Triaged

@gissuebot
Copy link
Author

Original comment posted by fry@google.com on 2011-12-05 at 06:48 PM


We don't see this enhancement bearing the weight of the added API complexity.


Status: WontFix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant