T
- Type this Reducer operates onpublic interface Reducer<T> extends Monoid<T>
Modifier and Type | Method and Description |
---|---|
static <T> Reducer<T> |
fromMonoid(Monoid<T> monoid,
java.util.function.Function<?,? extends T> mapper) |
default T |
mapReduce(java.util.stream.Stream<?> toReduce)
Map a given Stream to required type (via mapToType method), then
reduce using this monoid
Example of multiple reduction using multiple Monoids and PowerTuples
|
default java.util.stream.Stream<T> |
mapToType(java.util.stream.Stream<?> stream)
Map this reducer to the supported Type t.
|
static <T> Reducer<T> |
of(T zero,
java.util.function.BiFunction<T,T,T> combiner,
java.util.function.Function<?,? extends T> mapToType) |
static <T> Reducer<T> |
of(T zero,
java.util.function.Function<T,java.util.function.Function<T,T>> combiner,
java.util.function.Function<?,T> mapToType) |
default java.util.stream.Stream<T> mapToType(java.util.stream.Stream<?> stream)
stream
- Stream to convertdefault T mapReduce(java.util.stream.Stream<?> toReduce)
Monoid<Integer> sum = Monoid.of(0,(a,b)->a+b);
Monoid<Integer> mult = Monoid.of(1,(a,b)->a*b);
<PTuple2<Integer,Integer>> result = PowerTuples.tuple(sum,mult).<PTuple2<Integer,Integer>>asReducer()
.mapReduce(Stream.of(1,2,3,4));
assertThat(result,equalTo(tuple(10,24)));
toReduce
- Stream to reducestatic <T> Reducer<T> fromMonoid(Monoid<T> monoid, java.util.function.Function<?,? extends T> mapper)
static <T> Reducer<T> of(T zero, java.util.function.BiFunction<T,T,T> combiner, java.util.function.Function<?,? extends T> mapToType)
static <T> Reducer<T> of(T zero, java.util.function.Function<T,java.util.function.Function<T,T>> combiner, java.util.function.Function<?,T> mapToType)