public interface Semigroup<A>
sumNonEmpty(Object, Iterable) and
multiply1p(int, Object) can be overriden for performance reason,
especially if sumNonEmpty(Object, Iterable) can be implemented to
not require evaluation of the whole iterable.Monoid| Modifier and Type | Method and Description |
|---|---|
A |
append(A a1,
A a2)
Combine the two given arguments.
|
static <A,B> Semigroup<Pair<A,B>> |
compose(Semigroup<A> sa,
Semigroup<B> sb)
Composes a semigroup with another.
|
static <A> Semigroup<A> |
dual(Semigroup<A> semigroup)
Return the dual Semigroup of a semigroup
|
default A |
multiply1p(int n,
A a)
Returns a value summed
n + 1 times (
a + a + ... |
default A |
sumNonEmpty(A head,
Iterable<A> tail)
Reduce a 'non-empty' Iterable with
append(Object, Object) |
A append(A a1, A a2)
a1 - left value to combinea2 - right value to combinedefault A sumNonEmpty(A head, Iterable<A> tail)
append(Object, Object)head - the head of the 'non-empty' Iterabletail - the tail (maybe an empty Iterable).default A multiply1p(int n, A a)
n + 1 times (
a + a + ... + a) The default definition uses peasant
multiplication, exploiting associativity to only require `O(log n)` uses of
append(Object, Object).n - multipliera - the value to be reapeatly summed n + 1 timesa summed n times. If n <= 0, returns
zero()static <A,B> Semigroup<Pair<A,B>> compose(Semigroup<A> sa, Semigroup<B> sb)
Copyright © 2017 Atlassian. All rights reserved.