Class MonoidLaws<A>

java.lang.Object
io.atlassian.fugue.law.MonoidLaws<A>

public final class MonoidLaws<A> extends Object
Laws for a monoid
  • Field Details

    • monoid

      private final Monoid<A> monoid
  • Constructor Details

    • MonoidLaws

      public MonoidLaws(Monoid<A> monoid)
      Build a law instance to check monoid properties
      Parameters:
      monoid - a Monoid to check matches the desired behaviors of
  • Method Details

    • 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 object
      y - an A object
      z - an A object
      Returns:
      a IsEq instance 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 IsEq where 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 IsEq where x is equal to append(x, zero())
    • sumEqualFold

      public IsEq<A> sumEqualFold(Iterable<A> as)
      The sum function of your monoid must be equal to Functions.fold(BiFunction, Object, Iterable) using append as the folding function and zero() as the initial value
      Parameters:
      as - a Iterable
      Returns:
      a IsEq where 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 containing n copies of the input type.
      Parameters:
      n - a int
      a - an A
      Returns:
      a IsEq where multiply(n,a) is equal to sum(take(n, cycle(a))