T
- public interface Monoid<T> extends Semigroup<T>
https://en.wikipedia.org/wiki/Monoid#Monoids_in_computer_science
Also inteded for use with Java 8 Streams (reduce method)
Practically the method signature to reduce matches the Monoid interface
Monoids could regrarded as immutable equivalents to JDK Collectors for Immutable ReductionFn2.FunctionalOperations<T1,T2,R>
Modifier and Type | Method and Description |
---|---|
default T |
foldLeft(java.util.stream.Stream<T> toFold) |
default T |
foldLeftI(java.lang.Iterable<T> toFold) |
default T |
foldLeftP(org.reactivestreams.Publisher<T> toFold) |
default <A> T |
foldMap(java.util.stream.Stream<A> toFoldMap,
java.util.function.Function<? super A,? extends T> mapFn) |
default <A> T |
foldMapI(java.lang.Iterable<A> toFoldMap,
java.util.function.Function<? super A,? extends T> mapFn) |
default <A> T |
foldMapP(org.reactivestreams.Publisher<A> toFoldMap,
java.util.function.Function<? super A,? extends T> mapFn) |
default T |
foldRight(java.util.stream.Stream<T> toFold) |
default T |
foldRightI(java.lang.Iterable<T> toFold) |
default T |
foldRightP(org.reactivestreams.Publisher<T> toFold) |
static <T> Monoid<T> |
fromBiFunction(T zero,
java.util.function.BiFunction<T,T,T> combiner)
Construct a Monoid from the supplied identity element and combining function
|
static <T> Monoid<T> |
of(T zero,
java.util.function.Function<T,java.util.function.Function<T,T>> combiner)
Construct a Monoid from the supplied identity element and combining function
|
static <T> Monoid<T> |
of(T zero,
Semigroup<T> group)
Construct a Monoid from the supplied identity element and Semigroup (combiner)
|
default T |
reduce(java.util.stream.Stream<T> toReduce)
Perform a reduction operation on the supplied Stream
|
default T |
reduceI(java.lang.Iterable<T> toReduce) |
default T |
reduceP(org.reactivestreams.Publisher<T> toReduce) |
T |
zero()
An element that when provided as a parameter to the combiner with another value, results
in the other value being returned
e.g.
|
T zero()
0 + 1 = 1 0 is zero() 1 * 2 = 2 1 is zero() "" + "hello" = "hello" "" is zero()
default T reduce(java.util.stream.Stream<T> toReduce)
toReduce
- Stream to reducedefault <A> T foldMap(java.util.stream.Stream<A> toFoldMap, java.util.function.Function<? super A,? extends T> mapFn)
default <A> T foldMapI(java.lang.Iterable<A> toFoldMap, java.util.function.Function<? super A,? extends T> mapFn)
default <A> T foldMapP(org.reactivestreams.Publisher<A> toFoldMap, java.util.function.Function<? super A,? extends T> mapFn)
static <T> Monoid<T> of(T zero, Semigroup<T> group)
zero
- Identity element (@see zero()
group
- Combining function or SemigroupSemigroups
static <T> Monoid<T> of(T zero, java.util.function.Function<T,java.util.function.Function<T,T>> combiner)
zero
- Identity element (@see zero()
combiner
- Combining functionstatic <T> Monoid<T> fromBiFunction(T zero, java.util.function.BiFunction<T,T,T> combiner)
zero
- Identity element (@see zero()
combiner
- Combining function