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) 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.- Since:
- 3.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionCombine the two given arguments.Composes a semigroup with another.static <A> Semigroup<A> Return the dual Semigroup of a semigroupdefault Amultiply1p(int n, A a) Returns a value summedn + 1times (a + a + ...default AsumNonEmpty(A head, Iterable<A> tail) Reduce a 'non-empty' Iterable withappend(Object, Object)
-
Method Details
-
append
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
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
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
Composes a semigroup with another. -
dual
Return the dual Semigroup of a semigroup- Parameters:
semigroup- base semigroup to create the dual from- Returns:
- a semigroup appending in reverse order
-