Interface Reducer<C,T>

Type Parameters:
C - the type of criteria
T - the element type
All Known Implementing Classes:
RankedReducer
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Reducer<C,T>
A functional interface whose implementations can either reduce a supplied List of elements representing a successful selection to a single element normally drawn or calculated from the selection according to some criteria, or fail gracefully in the face of ambiguity by invoking a supplied failure handler.

The reduction may be a simple filtering operation, or may be a summing or aggregating operation, or anything else.

This interface is conceptually subordinate to, but should not be confused with, the Reducible interface.

Reducer implementations are often used to help build Reducible implementations. See, for example, Reducible.ofCaching(Selectable, Reducer, BiFunction).

Author:
Laird Nelson
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default Reducer<C,T>
     
    static <C, T> T
    fail(List<? extends T> elements, C c)
     
    static <C, T> Reducer<C,T>
     
    static <C, T> Reducer<C,T>
     
    default T
    reduce(List<? extends T> elements, C c)
     
    reduce(List<? extends T> elements, C c, BiFunction<? super List<? extends T>,? super C,? extends T> failureHandler)
    Performs some kind of reductive or filtering operation on the supplied List, according to the supplied criteria, and returns the single result, or, if reduction fails, invokes the supplied BiFunction with a sublist representing a partial reduction (or an empty list representing a reduction that simply could not be performed), along with the supplied criteria, and returns its result.
    default T
    reduce(Selectable<? super C,? extends T> f, C c)
     
    default T
    reduce(Selectable<? super C,? extends T> f, C c, BiFunction<? super List<? extends T>,? super C,? extends T> failureHandler)
     
    static <A, B, C> C
    returnNull(A a, B b)
     
  • Method Details

    • reduce

      T reduce(List<? extends T> elements, C c, BiFunction<? super List<? extends T>,? super C,? extends T> failureHandler)
      Performs some kind of reductive or filtering operation on the supplied List, according to the supplied criteria, and returns the single result, or, if reduction fails, invokes the supplied BiFunction with a sublist representing a partial reduction (or an empty list representing a reduction that simply could not be performed), along with the supplied criteria, and returns its result.

      Implementations of this method must return determinate values.

      Parameters:
      elements - an immutable List to reduce; must not be null; represents a successful selection from a larger collection of elements
      c - the criteria effectively describing the initial selection and the desired reduction; may be null to indicate no criteria; may be ignored if not needed by an implementation
      failureHandler - a BiFunction receiving a failed reduction (usually a portion of the supplied elements), and the selection and reduction criteria, that returns a substitute reduction (or, more commonly, throws an exception); must not be null; must be invoked if reduction fails or undefined behavior may result
      Returns:
      a single, possibly null, element normally drawn or computed from the supplied elements, or a synthetic value returned by an invocation of the supplied failureHandler's BiFunction.apply(Object, Object) method
      Throws:
      NullPointerException - if elements or failureHandler is null
      ReductionException - if the failureHandler function throws a ReductionException
      See Also:
    • reduce

      default T reduce(Selectable<? super C,? extends T> f, C c, BiFunction<? super List<? extends T>,? super C,? extends T> failureHandler)
    • reduce

      default T reduce(Selectable<? super C,? extends T> f, C c)
    • reduce

      default T reduce(List<? extends T> elements, C c)
    • cached

      default Reducer<C,T> cached()
    • ofSimple

      static <C, T> Reducer<C,T> ofSimple()
    • ofFailing

      static <C, T> Reducer<C,T> ofFailing()
    • fail

      static <C, T> T fail(List<? extends T> elements, C c)
    • returnNull

      static <A, B, C> C returnNull(A a, B b)