Closed danieldietrich closed 8 years ago
Is this really necessary? You can just do .toJavaStream() and call collect(...) on that.
It is more concise. Also it works for all Values. It might be confusing to stream an Option for example because java.util.stream.Stream
is associated with collections.
I'm not really against it and I thought about it myself some time ago, but it's a bit bloaty in my opinion since you can do without and it's something you need very rarely. And btw, Option is a kind of collection! :wink:
I will think about it... we should only pull in changes that make sense.
Finished, we will keep it because they increase interoperability. In particular Collectors of other libraries can now be used in conjunction with Javslang. Many thanks @earlzero.
java.util.stream.Stream
has:collect(Collector<? super T,A,R> collector)
collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator, BiConsumer<R,R> combiner)
When we add these as
default
methods tojavaslang.Value
, Javaslang types will be ✨automagically✨ convertible to all libraries that are built on top ofjava.util.stream.Stream
(e.g. jooq/jool, amaembo/streamex, ...), but more important this allows us to re-use user-defined aggregation functions based on Collectors.Because this is a conversion method, we implement it in
Value
(orConvertible
) rather than inTraversable
.Iterator
will benefit from it because in a future Javaslang versionIterator
will not extendTraversable
any more (see #1295).