- Type Parameters:
C- the type of criteriaT- 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.
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 TypeMethodDescriptioncached()static <C,T> T static <C,T> Reducer <C, T> static <C,T> Reducer <C, T> ofSimple()default Treduce(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 suppliedList, according to the supplied criteria, and returns the single result, or, if reduction fails, invokes the suppliedBiFunctionwith 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 Treduce(Selectable<? super C, ? extends T> f, C c) default Treduce(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 suppliedList, according to the supplied criteria, and returns the single result, or, if reduction fails, invokes the suppliedBiFunctionwith 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 immutableListto reduce; must not benull; represents a successful selection from a larger collection of elementsc- the criteria effectively describing the initial selection and the desired reduction; may benullto indicate no criteria; may be ignored if not needed by an implementationfailureHandler- aBiFunctionreceiving a failed reduction (usually a portion of the suppliedelements), and the selection and reduction criteria, that returns a substitute reduction (or, more commonly, throws an exception); must not benull; must be invoked if reduction fails or undefined behavior may result- Returns:
- a single, possibly
null, element normally drawn or computed from the suppliedelements, or a synthetic value returned by an invocation of the suppliedfailureHandler'sBiFunction.apply(Object, Object)method - Throws:
NullPointerException- ifelementsorfailureHandlerisnullReductionException- if thefailureHandlerfunction throws aReductionException- See Also:
-
reduce
-
reduce
-
reduce
-
cached
-
ofSimple
-
ofFailing
-
fail
-
returnNull
-