Class Monoid<A>
java.lang.Object
fj.Monoid<A>
A monoid abstraction to be defined across types of the given type argument. Implementations must
follow the monoidal laws:
- Left Identity; forall x. sum(zero(), x) == x
- Right Identity; forall x. sum(x, zero()) == x
- Associativity; forall x y z. sum(sum(x, y), z) == sum(x, sum(y, z))
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacePrimitives functions of Monoid: alternative minimal definition and overridable methods.static interfacePrimitives functions of Monoid: minimal definition and overridable methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Monoid<BigDecimal> A monoid that adds big decimals.static final Monoid<BigDecimal> A monoid that multiplies big decimals.static final Monoid<BigInteger> A monoid that adds big integers.static final Monoid<BigInteger> A monoid that multiplies big integers.A monoid that ANDs booleans.private final Monoid.Definition<A> A monoid that ORs booleans.A monoid that XORs booleans.A monoid that adds integers.A monoid for the maximum of two integers.A monoid for the minimum of two integers.A monoid that multiplies integers.A monoid that adds longs.A monoid that multiplies longs.A monoid that adds natural numbers.A monoid that multiplies natural numbers.static final Monoid<StringBuffer> A monoid that appends string buffers.static final Monoid<StringBuilder> A monoid that appends string builders.A monoid that appends strings.A monoid for the Unit value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionA monoid for arrays.Composes this monoid with another.<B,C> Monoid <C> dual()Swaps the arguments when summing.A monoid for options that take the first available value.functionMonoid(Monoid<B> mb) A monoid for functions.A monoid for IO values.Intersperses the given value between each two elements of the iterable, and sums the result.A monoid for options that take the last available value.A monoid for lists.static <A> Monoid<A> Constructs a monoid from the given sum function and zero value, which must follow the monoidal laws.static <A> Monoid<A> Constructs a monoid from the given sum function and zero value, which must follow the monoidal laws.static <A> Monoid<A> monoidDef(Monoid.AltDefinition<A> def) Constructs a monoid from the given definition, which must follow the monoidal laws.static <A> Monoid<A> monoidDef(Monoid.Definition<A> def) Constructs a monoid from the given definition, which must follow the monoidal laws.static <A> Monoid<A> monoidDef(Semigroup.AltDefinition<A> s, A zero) Constructs a monoid from the given semigroup definition and zero value, which must follow the monoidal laws.static <A> Monoid<A> monoidDef(Semigroup.Definition<A> s, A zero) Constructs a monoid from the given semigroup definition and zero value, which must follow the monoidal laws.Returns a value summedntimes (a + a + ...optionMonoid(Semigroup<A> aSemigroup) Lift aSemigroup<A>for A to aMonoid<Option<A>>, using Option.none() as zero.Returns a semigroup projection of this monoid.setIntersectionMonoid(Bounded<A> bounded, Enumerator<A> enumerator) A intersection monoid for sets.A union monoid for sets.A monoid for streams.sum()Returns a function that sums according to this monoid.Returns a function that sums the given value according to this monoid.Sums the two given arguments.sumLeft()Returns a function that sums the given values with left-fold.Sums the given values with left-fold.Sums the given values with left-fold.sumLeftS()Returns a function that sums the given values with left-fold.sumRight()Returns a function that sums the given values with right-fold.Sums the given values with right-fold.Sums the given values with right-fold.<B> Monoid<B> Maps the given functions across this monoid as an invariant functor.zero()The zero value for this monoid.
-
Field Details
-
def
-
intAdditionMonoid
-
intMultiplicationMonoid
-
bigintAdditionMonoid
A monoid that adds big integers. -
bigintMultiplicationMonoid
A monoid that multiplies big integers. -
bigdecimalAdditionMonoid
A monoid that adds big decimals. -
bigdecimalMultiplicationMonoid
A monoid that multiplies big decimals. -
naturalAdditionMonoid
-
naturalMultiplicationMonoid
-
longAdditionMonoid
-
longMultiplicationMonoid
-
disjunctionMonoid
-
exclusiveDisjunctionMonoid
-
conjunctionMonoid
-
stringMonoid
-
stringBufferMonoid
A monoid that appends string buffers. -
stringBuilderMonoid
A monoid that appends string builders. -
intMaxMonoid
-
intMinMonoid
-
unitMonoid
-
-
Constructor Details
-
Monoid
-
-
Method Details
-
compose
-
semigroup
-
xmap
-
compose
-
sum
-
sum
-
sum
-
zero
-
multiply
Returns a value summedntimes (a + a + ... + a). The default definition uses peasant multiplication, exploiting associativity to only requireO(log n)uses ofsum(Object, Object).- Parameters:
n- multipliera- the value to be reapeatly summed- Returns:
asummedntimes. Ifn <= 0, returnszero()
-
sumRight
-
sumRight
-
sumLeft
-
sumLeft
-
sumLeft
-
sumRight
-
sumLeftS
-
join
Intersperses the given value between each two elements of the iterable, and sums the result.- Parameters:
as- An iterable of values to sum.a- The value to intersperse between values of the given iterable.- Returns:
- The sum of the given values and the interspersed value.
-
dual
-
monoidDef
Constructs a monoid from the given definition, which must follow the monoidal laws.- Parameters:
def- The definition for the monoid.- Returns:
- A monoid instance that uses the given sun function and zero value.
-
monoidDef
Constructs a monoid from the given definition, which must follow the monoidal laws.- Parameters:
def- The definition for the monoid.- Returns:
- A monoid instance that uses the given sun function and zero value.
-
monoidDef
Constructs a monoid from the given semigroup definition and zero value, which must follow the monoidal laws.- Parameters:
s- The semigroup definition for the monoid.zero- The zero for the monoid.- Returns:
- A monoid instance that uses the given sun function and zero value.
-
monoidDef
Constructs a monoid from the given semigroup definition and zero value, which must follow the monoidal laws.- Parameters:
s- The semigroup definition for the monoid.zero- The zero for the monoid.- Returns:
- A monoid instance that uses the given sun function and zero value.
-
monoid
Constructs a monoid from the given sum function and zero value, which must follow the monoidal laws. Java 8+ users: usemonoidDef(Semigroup.Definition, Object)instead.- Parameters:
sum- The sum function for the monoid.zero- The zero for the monoid.- Returns:
- A monoid instance that uses the given sun function and zero value.
-
monoid
Constructs a monoid from the given sum function and zero value, which must follow the monoidal laws. Java 8+ users: usemonoidDef(Semigroup.Definition, Object)instead.- Parameters:
sum- The sum function for the monoid.zero- The zero for the monoid.- Returns:
- A monoid instance that uses the given sun function and zero value.
-
functionMonoid
-
listMonoid
-
optionMonoid
-
firstOptionMonoid
-
lastOptionMonoid
-
streamMonoid
-
arrayMonoid
-
ioMonoid
-
setMonoid
-
setIntersectionMonoid
public static <A> Monoid<Set<A>> setIntersectionMonoid(Bounded<A> bounded, Enumerator<A> enumerator) A intersection monoid for sets.- Parameters:
bounded- A bound for all possible elementsenumerator- An enumerator for all possible elements- Returns:
- A monoid for sets whose elements have the given order.
-