Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8319173

Implement JEP 461: Stream Gatherers (Preview)

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 22
    • core-libs
    • None
    • source
    • minimal
    • Hide
      Since this implementation adds a single method to an existing interface, which has a default implementation, the only way I see it potentially interfering is for inadvertent overloads with similar-enough parameter types and lambdas of the same shape, where the compiler might not know which overload's parameter type it should try to convert a lambda to.
      Show
      Since this implementation adds a single method to an existing interface, which has a default implementation, the only way I see it potentially interfering is for inadvertent overloads with similar-enough parameter types and lambdas of the same shape, where the compiler might not know which overload's parameter type it should try to convert a lambda to.
    • Java API
    • SE

    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.

      Specification

      See attached specdiff archive.

      For more details, see: https://github.com/openjdk/jdk/pull/16420

      Attachments

        Issue Links

          Activity

            People

              vklang Viktor Klang
              vklang Viktor Klang
              Alan Bateman, Paul Sandoz
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: