Package fj
Class Semigroup<A>
java.lang.Object
fj.Semigroup<A>
Implementations must satisfy the law of associativity:
- Associativity; forall x. forall y. forall z. sum(sum(x, y), z) == sum(x, sum(y, z))
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Primitives functions of Semigroup: alternative minimal definition and overridable methods.static interface
Primitives functions of Semigroup: minimal definition and overridable methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Semigroup
<BigDecimal> A semigroup that adds big decimals.static final Semigroup
<BigDecimal> A semigroup that yields the maximum of big decimals.static final Semigroup
<BigDecimal> A semigroup that yields the minimum of big decimals.static final Semigroup
<BigDecimal> A semigroup that multiplies big decimals.static final Semigroup
<BigInteger> A semigroup that adds big integers.static final Semigroup
<BigInteger> A semigroup that yields the maximum of big integers.static final Semigroup
<BigInteger> A semigroup that yields the minimum of big integers.static final Semigroup
<BigInteger> A semigroup that multiplies big integers.A semigroup that ANDs booleans.private final Semigroup.Definition
<A> A semigroup that ORs booleans.A semigroup that XORs booleans.A semigroup that adds integers.A semigroup that yields the maximum of integers.A semigroup that yields the minimum of integers.A semigroup that multiplies integers.A semigroup that adds longs.A semigroup that yields the maximum of longs.A semigroup that yields the minimum of longs.A semigroup that multiplies longs.A semigroup that adds natural numbers.A semigroup that yields the maximum of natural numbers.A semigroup that yields the minimum of natural numbers.A semigroup that multiplies natural numbers.static final Semigroup
<StringBuffer> A semigroup that appends string buffers.static final Semigroup
<StringBuilder> A semigroup that appends string builders.A semigroup that appends strings.A semigroup for the Unit value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionA semigroup for arrays.<B,
C> Semigroup <C> dual()
Swaps the arguments when summing.A semigroup for optional values that take the first available value.static <A> Semigroup
<A> A semigroup which always uses the "first" (left-hand side) value.functionSemigroup
(Semigroup<B> sb) A semigroup for functions.ioSemigroup
(Semigroup<A> sa) A semigroup for IO values.A semigroup for optional values that take the last available value.static <A> Semigroup
<A> A semigroup which always uses the "last" (right-hand side) value.lift()
Lifts the semigroup to obtain a trivial monoid.A semigroup for lists.Constructs a monoid from this semigroup and a zero value, which must follow the monoidal laws.multiply1p
(int n, A a) Returns a value summedn + 1
times (a + a + ...
static <A> Semigroup
<NonEmptyList<A>> A semigroup for non-empty lists.p1Semigroup
(Semigroup<A> sa) A lazy semigroup for unary products.p2Semigroup
(Semigroup<A> sa, Semigroup<B> sb) A lazy semigroup for binary products.static <A> Semigroup
<A> Constructs a semigroup from the given function.static <A> Semigroup
<A> Constructs a semigroup from the given function.static <A> Semigroup
<A> semigroupDef
(Semigroup.AltDefinition<A> def) Constructs a semigroup from the given definition.static <A> Semigroup
<A> semigroupDef
(Semigroup.Definition<A> def) Constructs a semigroup from the given definition.A intersection semigroup for sets.A union semigroup for sets.A semigroup for streams.sum()
Returns a function that sums according to this semigroup.Returns a function that sums the given value according to this semigroup.Sums the two given arguments.sumNel
(NonEmptyList<A> as) Sums the given values with left-fold.Sums the given values with left-fold, shortcutting the computation as early as possible.<B> Semigroup
<B> Maps the given functions across this monoid as an invariant functor.
-
Field Details
-
def
-
intAdditionSemigroup
A semigroup that adds integers. -
intMultiplicationSemigroup
A semigroup that multiplies integers. -
intMaximumSemigroup
A semigroup that yields the maximum of integers. -
intMinimumSemigroup
A semigroup that yields the minimum of integers. -
bigintAdditionSemigroup
A semigroup that adds big integers. -
bigintMultiplicationSemigroup
A semigroup that multiplies big integers. -
bigintMaximumSemigroup
A semigroup that yields the maximum of big integers. -
bigintMinimumSemigroup
A semigroup that yields the minimum of big integers. -
bigdecimalAdditionSemigroup
A semigroup that adds big decimals. -
bigdecimalMultiplicationSemigroup
A semigroup that multiplies big decimals. -
bigDecimalMaximumSemigroup
A semigroup that yields the maximum of big decimals. -
bigDecimalMinimumSemigroup
A semigroup that yields the minimum of big decimals. -
naturalMultiplicationSemigroup
A semigroup that multiplies natural numbers. -
naturalAdditionSemigroup
A semigroup that adds natural numbers. -
naturalMaximumSemigroup
A semigroup that yields the maximum of natural numbers. -
naturalMinimumSemigroup
A semigroup that yields the minimum of natural numbers. -
longAdditionSemigroup
A semigroup that adds longs. -
longMultiplicationSemigroup
A semigroup that multiplies longs. -
longMaximumSemigroup
A semigroup that yields the maximum of longs. -
longMinimumSemigroup
A semigroup that yields the minimum of longs. -
disjunctionSemigroup
A semigroup that ORs booleans. -
exclusiveDisjunctionSemiGroup
A semigroup that XORs booleans. -
conjunctionSemigroup
A semigroup that ANDs booleans. -
stringSemigroup
A semigroup that appends strings. -
stringBufferSemigroup
A semigroup that appends string buffers. -
stringBuilderSemigroup
A semigroup that appends string builders. -
unitSemigroup
A semigroup for the Unit value.
-
-
Constructor Details
-
Semigroup
-
-
Method Details
-
sum
Sums the two given arguments.- Parameters:
a1
- A value to sum with another.a2
- A value to sum with another.- Returns:
- The of the two given arguments.
-
sum
Returns a function that sums the given value according to this semigroup.- Parameters:
a1
- The value to sum.- Returns:
- A function that sums the given value according to this semigroup.
-
sum
Returns a function that sums according to this semigroup.- Returns:
- A function that sums according to this semigroup.
-
multiply1p
Returns a value summedn + 1
times (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 n + 1 times- Returns:
a
summedn
times. Ifn <= 0
, returnszero()
-
sumNel
Sums the given values with left-fold. -
sumStream
Sums the given values with left-fold, shortcutting the computation as early as possible. -
dual
Swaps the arguments when summing. -
lift
Lifts the semigroup to obtain a trivial monoid. -
xmap
Maps the given functions across this monoid as an invariant functor.- Parameters:
f
- The covariant map.g
- The contra-variant map.- Returns:
- A new monoid.
-
compose
-
monoid
Constructs a monoid from this semigroup and a zero value, which must follow the monoidal laws.- Parameters:
zero
- The zero for the monoid.- Returns:
- A monoid instance that uses the given sun function and zero value.
-
semigroupDef
Constructs a semigroup from the given definition.- Parameters:
def
- The definition to construct this semigroup with.- Returns:
- A semigroup from the given definition.
-
semigroupDef
Constructs a semigroup from the given definition.- Parameters:
def
- The definition to construct this semigroup with.- Returns:
- A semigroup from the given definition.
-
semigroup
Constructs a semigroup from the given function. Java 8+ users: usesemigroupDef(AltDefinition)
instead.- Parameters:
sum
- The function to construct this semigroup with.- Returns:
- A semigroup from the given function.
-
semigroup
Constructs a semigroup from the given function. Java 8+ users: usesemigroupDef(Definition)
instead.- Parameters:
sum
- The function to construct this semigroup with.- Returns:
- A semigroup from the given function.
-
firstSemigroup
A semigroup which always uses the "first" (left-hand side) value. -
lastSemigroup
A semigroup which always uses the "last" (right-hand side) value. -
functionSemigroup
A semigroup for functions.- Parameters:
sb
- The smeigroup for the codomain.- Returns:
- A semigroup for functions.
-
listSemigroup
A semigroup for lists.- Returns:
- A semigroup for lists.
-
nonEmptyListSemigroup
A semigroup for non-empty lists.- Returns:
- A semigroup for non-empty lists.
-
firstOptionSemigroup
A semigroup for optional values that take the first available value.- Returns:
- A semigroup for optional values that take the first available value.
-
lastOptionSemigroup
A semigroup for optional values that take the last available value.- Returns:
- A semigroup for optional values that take the last available value.
-
streamSemigroup
A semigroup for streams.- Returns:
- A semigroup for streams.
-
arraySemigroup
A semigroup for arrays.- Returns:
- A semigroup for arrays.
-
p1Semigroup
A lazy semigroup for unary products.- Parameters:
sa
- A semigroup for the product's type.- Returns:
- A semigroup for unary products.
-
p2Semigroup
A lazy semigroup for binary products.- Parameters:
sa
- A semigroup for the product's first type.sb
- A semigroup for the product's second type.- Returns:
- A semigroup for binary products.
-
ioSemigroup
A semigroup for IO values. -
setSemigroup
A union semigroup for sets.- Returns:
- a semigroup for sets.
-
setIntersectionSemigroup
A intersection semigroup for sets.- Returns:
- a semigroup for sets.
-