|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
B - A - public interface Reduction<A,B>
A Reduction are aggregate-functions-like objects that encapsulates a
computation with effect that processes each element of a sequence of objects,
calculating intermediate, accumulative results. The last accumulation is the
final result of the reduction over such sequence.
Reductions can be applied to potentially any sequence of objects:
Iterables, InputStreams, etc.
Although Reductions implement aggregation in an impure manner - its
newAccumulator() message will return a mutable Accumulator -
they are sharable, since Reduction itself are stateless
SideEffectFree,
Function| Method Summary | ||
|---|---|---|
Accumulator<A,B> |
newAccumulator()
Answers a new, reseted accumulator to perform the reduction |
|
|
of(Applicable<D,A> function)
Composes this reduction with a function, by returning a new Reduction that will apply this reduction to the results of
applying the given function to each element
For example, the following code:
Reductions. |
|
|
then(Applicable<B,D> function)
Composes the given function with this reduction, by returning a new Reduction that applies the function to the resulting
element of the reduction
For example, the following code:
Reductions. |
|
| Method Detail |
|---|
@NonNull Accumulator<A,B> newAccumulator()
Accumulator<D> Reduction<A,D> then(Applicable<B,D> function)
Reduction that applies the function to the resulting
element of the reduction
For example, the following code:
Reductions.<Strin> max().then(Strings.length())will return a reduction that computes the length of the maximum - lexicographically - string it processes:
accumulator = lengthOfMax.newAccumulator();
accumulator.accumulate("aaa");
accumulator.accumulate("bbbbb");
accumulator.accumulate("dd");
accumulator.value() // 2, because length of "dd", the max string, is 2
function -
<D> Reduction<D,B> of(Applicable<D,A> function)
Reduction that will apply this reduction to the results of
applying the given function to each element
For example, the following code:
Reductions.<Integer> max().of(Strings.length())will return a reduction that computes the maximum length of the strings it processes:
accumulator = maxLength.newAccumulator();
accumulator.accumulate("aaa");
accumulator.accumulate("bbbbb");
accumulator.accumulate("dd");
accumulator.value() // 5, because "bbbbb" has the max length, which is 5
function -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||