We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Noticed a lot of code looks like this:
ImmutableMap<Integer, String> map = Stream.of(1, 2, 3, 4, 5) .map(i -> Maps.immutableEntry(i, String.valueOf(i))) .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
Would be nice if there was a collector for collecting Stream<Map.Entry<K, V>> into ImmutableMap<K, V> so the above can look like:
Stream<Map.Entry<K, V>>
ImmutableMap<K, V>
ImmutableMap<Integer, String> map = Stream.of(1, 2, 3, 4, 5) .map(i -> Maps.immutableEntry(i, String.valueOf(i))) .collect(toImmutableMap());
The collector can be implemented like:
static <K, V> Collector<Map.Entry<K, V>, ?, ImmutableMap<K, V>> toImmutableMap() { return ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue); }
The text was updated successfully, but these errors were encountered:
Isn't
ImmutableMap<Integer, String> map = Stream.of(1, 2, 3, 4, 5) .collect(toImmutableMap(i -> i, String::valueOf));
even nicer? ;)
Sorry, something went wrong.
Also, this issue seems to be related to #2632.
Lol sorry my example wasn't very good.
Usually the Stream<Map.Entry> is created from entrySet().stream().
Stream<Map.Entry>
entrySet().stream()
Also have seen it with flatmap. E.g.
flatmap
ImmutableMap<String, Integer> map = Stream.of(1, 2, 3) .flatMap(i -> Stream.of("A", "B", "C").map(s -> Maps.immutableEntry(s + i, i))) .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
Have also seen streams of Table.Cell with
Table.Cell
.collect(toImmutableTable(Table.Cell::getRowKey, Table.Cell::getColumnKey, Table.Cell::getValue));
Successfully merging a pull request may close this issue.
Noticed a lot of code looks like this:
Would be nice if there was a collector for collecting
Stream<Map.Entry<K, V>>
intoImmutableMap<K, V>
so the above can look like:The collector can be implemented like:
The text was updated successfully, but these errors were encountered: