Class SemigroupLaws<A>

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

public final class SemigroupLaws<A> extends Object
Laws for a semigroup
  • Field Details

    • semigroup

      private final Semigroup<A> semigroup
  • Constructor Details

    • SemigroupLaws

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

    • semigroupAssociative

      public IsEq<A> semigroupAssociative(A x, A y, A z)
      A semigroup 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))
    • sumNonEmptyEqualFold

      public IsEq<A> sumNonEmptyEqualFold(A head, Iterable<A> tail)
      The Semigroup.sumNonEmpty(Object, Iterable) function of your semigroup must be equal to a Functions.fold(BiFunction, Object, Iterable) where append is used as the combining function, head is used as the initial value and tail is the iterable to check
      Parameters:
      head - an A
      tail - a Iterable of A's
      Returns:
      a IsEq where sumeNonEmpty(head, tail) is equal to fold(append, head, tail)
    • multiply1pEqualRepeatedAppend

      public IsEq<A> multiply1pEqualRepeatedAppend(int n, A a)
      The Semigroup.multiply1p(int, Object) function of your semigroup must be equal to Semigroup.sumNonEmpty(Object, Iterable) applied to the input and an iterable containing n - 1 copies of that input
      Parameters:
      n - a int representing the number of copies of the input to combine
      a - an A
      Returns:
      a IsEq where multiply(n,a) is equal to sumNonEmpty(a, take(n-1, cycle(a))