Package io.atlassian.fugue
Interface Semigroup<A>
-
- All Known Subinterfaces:
Monoid<A>
public interface Semigroup<A>A Semigroup is an algebraic structure consisting of an associative binary operation across the values of a given type (the Semigroup type argument). Implementations must satisfy the law of associativity:- Associativity; forall x y z. append(append(x, y), z) == append(x, append(y, z))
sumNonEmpty(Object, Iterable)andmultiply1p(int, Object)can be overriden for performance reason, especially ifsumNonEmpty(Object, Iterable)can be implemented to not require evaluation of the whole iterable.- Since:
- 3.1
- See Also:
Monoid
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Aappend(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 semigroupdefault Amultiply1p(int n, A a)Returns a value summedn + 1times (a + a + ...default AsumNonEmpty(A head, java.lang.Iterable<A> tail)Reduce a 'non-empty' Iterable withappend(Object, Object)
-
-
-
Method Detail
-
append
A append(A a1, A a2)
Combine the two given arguments.- Parameters:
a1- left value to combinea2- right value to combine- Returns:
- the combination of the left and right value.
-
sumNonEmpty
default A sumNonEmpty(A head, java.lang.Iterable<A> tail)
Reduce a 'non-empty' Iterable withappend(Object, Object)- Parameters:
head- the head of the 'non-empty' Iterabletail- the tail (maybe an empty Iterable).- Returns:
- the sum of all elements.
-
multiply1p
default A multiply1p(int n, A a)
Returns a value summedn + 1times (a + a + ... + a) The default definition uses peasant multiplication, exploiting associativity to only require `O(log n)` uses ofappend(Object, Object).- Parameters:
n- multipliera- the value to be reapeatly summed n + 1 times- Returns:
asummedntimes. Ifn <= 0, returnszero()
-
compose
static <A,B> Semigroup<Pair<A,B>> compose(Semigroup<A> sa, Semigroup<B> sb)
Composes a semigroup with another.
-
-