JDK-8319173 : Implement JEP 461: Stream Gatherers (Preview)
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.util.stream
  • Priority: P4
  • Status: Finalized
  • Resolution: Unresolved
  • Fix Versions: 22
  • Submitted: 2023-10-31
  • Updated: 2023-11-18
Related Reports
CSR :  
Description
Summary
-------

Introduces `Stream::gather(Gatherer)`, the `java.util.stream.Gatherer` interface, and the class for built-in Gatherer operations named `java.util.stream.Gatherers`.

Problem
-------

`java.util.stream.Stream` does not have an intermediate operation which allows to serve as a vehicle for implementing generic user-defined intermediate operations.

Solution
--------

We introduce `java.util.stream.Stream::gather(Gatherer)` as the entry-point for attaching user-defined intermediate operations -- "Stream Gatherers".  In order to ensure binary compatibility, a default implementation of this method is provided.

We also define the `java.util.stream.Gatherer` interface, which allows the Java Standard Library, and Java developers, to implement new intermediate operations that can be attached to `java.util.stream.Stream` using the `gather(Gatherer)`-method. Gatherer's API design is heavily inspired by `java.util.stream.Collector`, and the runtime evaluation thereof draws from existing implementations in the JDK.

In order to provide built-in Gatherers to Java developers, the `java.util.stream.Gatherers` class is introduced, which exposes the following public static methods: `fold`, `mapConcurrent`, `scan`, `windowFixed`, `windowSliding` -- and all of them return a Gatherer describing that respective operation given a set of parameter values.

Alternatives have been discussed [here](https://cr.openjdk.org/~vklang/Gatherers.html).

Specification
-------------

See attached specdiff archive.

For more details, see: https://github.com/openjdk/jdk/pull/16420 
Comments
Re-affirming Provisional status for the updated request; thanks.
17-11-2023

[~darcy] Thanks for the feedback. 1 non-@implSpec default method was found and has been addressed. The specdiff archive attached to this CSR has been updated to reflect this change, and the Pull-Request for JEP-461 implementation has been updated to reflect this change as well.
17-11-2023

Moving to Provisional, not Approved. Please double-check all default methods have implSpec tags.
17-11-2023