Interface Gatherer<I,ACC,O>

Type Parameters:
I - the type of the items emitted by the upstream
ACC - the type of the accumulator
O - the type of the items emitted to the downstream
All Known Implementing Classes:
Gatherers.DefaultGatherer

@Experimental("This API is still being designed and may change in the future") public interface Gatherer<I,ACC,O>
A Gatherer operator transforms a stream of items by accumulating them into an accumulator and extracting items from that accumulator when certain conditions are met.
  • Method Details

    • accumulator

      ACC accumulator()
      Creates a new accumulator.
      Returns:
      a new accumulator
    • accumulate

      ACC accumulate(ACC accumulator, I item)
      Accumulates an item into the accumulator.
      Parameters:
      accumulator - the current accumulator
      item - the item to accumulate
      Returns:
      the updated accumulator
    • extract

      Optional<Gatherer.Extraction<ACC,O>> extract(ACC accumulator, boolean upstreamCompleted)
      Extracts an item from the accumulator.
      Parameters:
      accumulator - the current accumulator
      upstreamCompleted - whether the upstream has completed
      Returns:
      an Optional containing a Extraction with the updated accumulator and the extracted item, or an empty Optional if no item can be extracted
    • finalize

      Optional<O> finalize(ACC accumulator)
      Finalizes the accumulator and extracts the final item, if any. This method is called when the upstream has completed and no more items can be extracted using the extract method.
      Parameters:
      accumulator - the current accumulator
      Returns:
      an Optional containing the final item, or an empty Optional if no final item can be extracted