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 ReductionModifier and Type | Method and Description |
---|---|
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
|
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 reducestatic <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