Class Reducer

java.lang.Object
net.pincette.rs.Reducer

public class Reducer extends Object
Functions to reduce a publisher and return the result as a CompletionStage.
Since:
1.1
Author:
Werner Donné
  • Method Details

    • forEach

      public static <T> CompletionStage<Void> forEach(Flow.Publisher<T> publisher, Consumer<T> consumer)
      Runs consumer for each emitted value.
      Type Parameters:
      T - the value type of the publisher.
      Parameters:
      publisher - the given publisher.
      consumer - the consumer function.
      Returns:
      The completion stage.
      Since:
      1.4.1
    • forEachJoin

      public static <T> void forEachJoin(Flow.Publisher<T> publisher, Consumer<T> consumer)
      Runs consumer for each emitted value and makes it synchronous.
      Type Parameters:
      T - the value type of the publisher.
      Parameters:
      publisher - the given publisher.
      consumer - the consumer function.
      Since:
      1.4.1
    • reduce

      public static <T, U> CompletionStage<U> reduce(Flow.Publisher<T> publisher, Supplier<U> identity, BiFunction<U,T,U> accumulator)
      Accumulates all the values emitted by the publisher into a new value.
      Type Parameters:
      T - the value type of the publisher.
      U - the value type of the result.
      Parameters:
      publisher - the given publisher.
      identity - the function to produce the initial accumulated value.
      accumulator - the function to accumulate all the values.
      Returns:
      The completion stage with the result.
      Since:
      1.1
    • reduce

      public static <T> CompletionStage<Optional<T>> reduce(Flow.Publisher<T> publisher, BinaryOperator<T> accumulator)
      Accumulates all the values emitted by the publisher by combining them.
      Type Parameters:
      T - the value type.
      Parameters:
      publisher - the given publisher.
      accumulator - the associative function that combines the values.
      Returns:
      The completion stage with the result. The optional will be empty when the publisher didn't emit any values before completing.
      Since:
      1.1
    • reduceJoin

      public static <T, U> U reduceJoin(Flow.Publisher<T> publisher, Supplier<U> identity, BiFunction<U,T,U> accumulator)
      Accumulates all the values emitted by the publisher into a new value and makes it synchronous.
      Type Parameters:
      T - the value type of the publisher.
      U - the value type of the result.
      Parameters:
      publisher - the given publisher.
      identity - the function to produce the initial accumulated value.
      accumulator - the function to accumulate all the values.
      Returns:
      The completion stage with the result.
      Since:
      1.4.1
    • reduceJoin

      public static <T> Optional<T> reduceJoin(Flow.Publisher<T> publisher, BinaryOperator<T> accumulator)
      Accumulates all the values emitted by the publisher by combining them and makes it synchronous.
      Type Parameters:
      T - the value type.
      Parameters:
      publisher - the given publisher.
      accumulator - the associative function that combines the values.
      Returns:
      The completion stage with the result. The optional will be empty when the publisher didn't emit any values before completing.
      Since:
      1.4.1