-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
Hi,
I see that CapsuleCollectors.toMap
is commented in the code. Is there any reason not to make it available?
That's how I reimplemented it:
public static <T, K, V> Collector<T, ?, io.usethesource.capsule.Map.Immutable<K, V>> toMap(
Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper
) {
/** extract key/value from type {@code T} and insert into map */
final BiConsumer<io.usethesource.capsule.Map.Transient<K, V>, T> accumulator =
(map, element) -> map.__put(keyMapper.apply(element), valueMapper.apply(element));
return new DefaultCollector<>(
io.usethesource.capsule.Map.Transient::of,
accumulator,
(left, right) -> {
left.__putAll(right);
return left;
},
io.usethesource.capsule.Map.Transient::freeze,
CapsuleCollectors.UNORDERED
);
}
Another one would be the same but using a function to merge values in case one already exists in the transient map.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels