Package io.atlassian.fugue.law
Class MonoidLaws<A>
- java.lang.Object
-
- io.atlassian.fugue.law.MonoidLaws<A>
-
public final class MonoidLaws<A> extends java.lang.ObjectLaws for a monoid
-
-
Constructor Summary
Constructors Constructor Description MonoidLaws(Monoid<A> monoid)Build a law instance to check monoid properties
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IsEq<A>monoidLeftIdentity(A x)If the zero of your monoid is combine with an element of the type your monoid works with the result should be that element.IsEq<A>monoidRightIdentity(A x)If an element of the type your monoid works with is combined with the zero of your monoid result should be that element.IsEq<A>multiplyEqualRepeatedAppend(int n, A a)The multiply function of your monoid must be equal to the sum function called with an iterable containingncopies of the input type.IsEq<A>semigroupAssociative(A x, A y, A z)A monoid must not care about the order elements are combined.IsEq<A>sumEqualFold(java.lang.Iterable<A> as)The sum function of your monoid must be equal toFunctions.fold(BiFunction, Object, Iterable)using append as the folding function and zero() as the initial value
-
-
-
Method Detail
-
semigroupAssociative
public IsEq<A> semigroupAssociative(A x, A y, A z)
A monoid must not care about the order elements are combined. If you combine x with y and then with z the result should be the same as combining y with z and then with x.- Parameters:
x- an A objecty- an A objectz- an A object- Returns:
- a
IsEqinstance where append(append(x,y),z) is equal to append(x, append(y,z))
-
monoidLeftIdentity
public IsEq<A> monoidLeftIdentity(A x)
If the zero of your monoid is combine with an element of the type your monoid works with the result should be that element.- Parameters:
x- an element of your monoid type- Returns:
- a
IsEqwhere x is equal to append(zero(), x)
-
monoidRightIdentity
public IsEq<A> monoidRightIdentity(A x)
If an element of the type your monoid works with is combined with the zero of your monoid result should be that element.- Parameters:
x- an element of your monoid type- Returns:
- a
IsEqwhere x is equal to append(x, zero())
-
sumEqualFold
public IsEq<A> sumEqualFold(java.lang.Iterable<A> as)
The sum function of your monoid must be equal toFunctions.fold(BiFunction, Object, Iterable)using append as the folding function and zero() as the initial value- Parameters:
as- aIterable- Returns:
- a
IsEqwhere sum(as) is equal to fold(append, zero, as)
-
multiplyEqualRepeatedAppend
public IsEq<A> multiplyEqualRepeatedAppend(int n, A a)
The multiply function of your monoid must be equal to the sum function called with an iterable containingncopies of the input type.- Parameters:
n- a inta- an A- Returns:
- a
IsEqwhere multiply(n,a) is equal to sum(take(n, cycle(a))
-
-