public interface Monoid<A> extends Semigroup<A>
Semigroup)
and an identity element for this operation. Implementations must follow the
monoidal laws:
sum(Iterable) and multiply(int, Object) can be
overriden for performance reason, especially if sum(Iterable) can be
implemented to not require evaluation of the whole iterable. All other
default methods should not be overriden.Semigroup| Modifier and Type | Method and Description |
|---|---|
static <A,B> Monoid<Pair<A,B>> |
compose(Monoid<A> ma,
Monoid<B> mb)
Composes a monoid with another.
|
static <A> Monoid<A> |
dual(Monoid<A> monoid)
Return the dual Monoid.
|
default A |
intersperse(Iterable<? extends A> as,
A a)
Intersperses the given value between each two elements of the collection,
and sums the result.
|
default A |
multiply(int n,
A a)
Returns a value summed
n times (a + a + ... |
default A |
multiply1p(int n,
A a)
Returns a value summed
n + 1 times (
a + a + ... |
default A |
sum(Iterable<A> as)
Sums the given values.
|
default A |
sumNonEmpty(A head,
Iterable<A> tail)
Reduce a 'non-empty' Iterable with
Semigroup.append(Object, Object) |
A |
zero()
The identity element value for this monoid.
|
A zero()
default A sum(Iterable<A> as)
as - The values to sum.default A multiply(int n, A a)
n times (a + a + ... + a).
The default definition uses peasant multiplication, exploiting
associativity to only require `O(log n)` uses of
Semigroup.append(Object, Object).n - multipliera - the value to be reapeatly summeda summed n times. If n <= 0, returns
zero()default A intersperse(Iterable<? extends A> as, A a)
as - An iterable of values.a - The value to intersperse between values of the given iterable.default A sumNonEmpty(A head, Iterable<A> tail)
SemigroupSemigroup.append(Object, Object)sumNonEmpty in interface Semigroup<A>head - the head of the 'non-empty' Iterabletail - the tail (maybe an empty Iterable).default A multiply1p(int n, A a)
Semigroupn + 1 times (
a + a + ... + a) The default definition uses peasant
multiplication, exploiting associativity to only require `O(log n)` uses of
Semigroup.append(Object, Object).multiply1p in interface Semigroup<A>n - multipliera - the value to be reapeatly summed n + 1 timesa summed n times. If n <= 0, returns
zero()static <A,B> Monoid<Pair<A,B>> compose(Monoid<A> ma, Monoid<B> mb)
Copyright © 2017 Atlassian. All rights reserved.