Class MonoidLaws<A>


  • public final class MonoidLaws<A>
    extends java.lang.Object
    Laws for a monoid
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Monoid<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 containing n copies 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 to Functions.fold(BiFunction, Object, Iterable) using append as the folding function and zero() as the initial value
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • monoid

        private final Monoid<A> monoid
    • Constructor Detail

      • 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 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 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​(java.lang.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))