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
Comments
Original comment posted by dancerjohn on 2011-09-22 at 12:11 PM These signatures match those suggested in issue #679 |
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))) |
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. |
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: |
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: |
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.
The text was updated successfully, but these errors were encountered: