jOOλ - The Missing Parts in Java 8 jOOλ improves the JDK libraries in areas where the Expert Group's focus was elsewhere. It adds tuple support, function support, and a lot of additional functionality around sequential Streams. The JDK 8's main efforts (default methods, lambdas, and the Stream API) were focused around maintaining backwards compatibility and implementing a functional API for parallelism.
// Unfortunately, Java's type inference might need
// a little help here
var percentiles =
Stream.of(1, 2, 3, 4, 10, 9, 3, 3).collect(
Tuple.collectors(
Agg.<Integer>percentile(0.0),
Agg.<Integer>percentile(0.25),
Agg.<Integer>percentile(0.5),
Agg.<Integer>percentile(0.75),
Agg.<Integer>percentile(1.0)
)
);
System.out.println(percentiles);
Wrapping the collectors explicitly shouldn't be necessary, really. It would be nice to have overloaded collect() methods that allow for collecting into a tuple directly:
// Unfortunately, Java's type inference might need
// a little help here
var percentiles =
Stream.of(1, 2, 3, 4, 10, 9, 3, 3).collect(
Agg.percentile(0.0),
Agg.percentile(0.25),
Agg.percentile(0.5),
Agg.percentile(0.75),
Agg.percentile(1.0)
);
System.out.println(percentiles);
Type inference tends not to work very well when using
Tuple.collectors()
. A type witness is often needed as can be seen in this post: https://blog.jooq.org/2019/02/11/lesser-known-joo%CE%BB-features-useful-collectorsWrapping the collectors explicitly shouldn't be necessary, really. It would be nice to have overloaded
collect()
methods that allow for collecting into a tuple directly: