Interface Gatherers


@Experimental("This API is still being designed and may change in the future") public interface Gatherers
Factory interface for creating Gatherer instances.

This interface provides various static methods to create different types of gatherers.

  • Method Details

    • of

      static <I, ACC, O> Gatherer<I,ACC,O> of(Supplier<ACC> initialAccumulatorSupplier, BiFunction<ACC,I,ACC> accumulatorFunction, BiFunction<ACC,Boolean,Optional<Gatherer.Extraction<ACC,O>>> extractor, Function<ACC,Optional<O>> finalizer)
      Creates a new Gatherer with the specified components.
      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
      Parameters:
      initialAccumulatorSupplier - the supplier for the initial accumulator
      accumulatorFunction - the function to accumulate items into the accumulator
      extractor - the function to extract items from the accumulator
      finalizer - the function to extract the final item from the accumulator
      Returns:
      a new Gatherer
    • scan

      static <I> Gatherer<I,I,I> scan(Supplier<I> initialAccumulatorSupplier, BiFunction<I,I,I> accumulatorFunction)
      Creates a new Gatherer that performs a scan operation. The scan operation applies a function to each item emitted by the upstream, using the result of the previous application as the first argument to the function. The initial value is provided by the initialAccumulatorSupplier.

      Each intermediate result is emitted downstream.

      Type Parameters:
      I - the type of the items emitted by the upstream and downstream
      Parameters:
      initialAccumulatorSupplier - the supplier for the initial accumulator
      accumulatorFunction - the function to accumulate items
      Returns:
      a new Gatherer that performs a scan operation
    • fold

      static <I> Gatherer<I,I,I> fold(Supplier<I> initialAccumulatorSupplier, BiFunction<I,I,I> accumulatorFunction)
      Creates a new Gatherer that performs a fold operation. The fold operation applies a function to each item emitted by the upstream, using the result of the previous application as the first argument to the function. The initial value is provided by the initialAccumulatorSupplier.

      Only emits the final result when the upstream completes.

      Type Parameters:
      I - the type of the items emitted by the upstream and downstream
      Parameters:
      initialAccumulatorSupplier - the supplier for the initial accumulator
      accumulatorFunction - the function to accumulate items
      Returns:
      a new Gatherer that performs a fold operation
    • window

      static <I> Gatherer<I,List<I>,List<I>> window(int size)
      Creates a new Gatherer that performs a windowing operation. The windowing operation collects items emitted by the upstream into non-overlapping windows of the specified size. When a window is full, it is emitted downstream and a new window is started. If the upstream completes before a window is full, the current window is emitted if it is not empty.
      Type Parameters:
      I - the type of the items emitted by the upstream
      Parameters:
      size - the size of the window
      Returns:
      a new Gatherer that performs a windowing operation
    • slidingWindow

      static <I> Gatherer<I,List<I>,List<I>> slidingWindow(int size)
      Creates a new Gatherer that performs a sliding window operation. The sliding window operation collects items emitted by the upstream into overlapping windows of the specified size. When a window is full, it is emitted downstream and a new window is started with all but the first item from the previous window. If the upstream completes before a window is full, the current window is emitted if it is not empty.
      Type Parameters:
      I - the type of the items emitted by the upstream
      Parameters:
      size - the size of the window
      Returns:
      a new Gatherer that performs a sliding window operation
    • builder

      static <I> Gatherer.Builder<I> builder()
      Creates a new Gatherer builder.
      Type Parameters:
      I - the type of the items emitted by the upstream
      Returns:
      the builder