Package io.atlassian.fugue.law
Class MonoidLaws<A>
java.lang.Object
io.atlassian.fugue.law.MonoidLaws<A>
Laws for a monoid
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMonoidLaws(Monoid<A> monoid) Build a law instance to check monoid properties -
Method Summary
Modifier and TypeMethodDescriptionIf the zero of your monoid is combine with an element of the type your monoid works with the result should be that element.If an element of the type your monoid works with is combined with the zero of your monoid result should be that element.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.semigroupAssociative(A x, A y, A z) A monoid must not care about the order elements are combined.sumEqualFold(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
-
Field Details
-
monoid
-
-
Constructor Details
-
MonoidLaws
Build a law instance to check monoid properties- Parameters:
monoid- aMonoidto check matches the desired behaviors of
-
-
Method Details
-
semigroupAssociative
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
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
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
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 -
multiplyEqualRepeatedAppend
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))
-