vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.74k stars 637 forks source link

Add Java-like Value.collect() methods to increase interoperability #1332

Closed danieldietrich closed 8 years ago

danieldietrich commented 8 years ago

java.util.stream.Stream has:

When we add these as default methods to javaslang.Value, Javaslang types will be ✨automagically✨ convertible to all libraries that are built on top of java.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 (or Convertible) rather than in Traversable. Iterator will benefit from it because in a future Javaslang version Iterator will not extend Traversable any more (see #1295).

mvh77 commented 8 years ago

Is this really necessary? You can just do .toJavaStream() and call collect(...) on that.

danieldietrich commented 8 years ago

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.

mvh77 commented 8 years ago

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:

danieldietrich commented 8 years ago

I will think about it... we should only pull in changes that make sense.

danieldietrich commented 8 years ago

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.