@Theory public void unitLaw(Integer x) { Integer left = sumMonoid.multiply(0, x); Integer right = sumMonoid.multiply(x, 0); assertThat(left, is(x)); assertThat(right, is(x)); }
/** * Folds this tree using the given monoid. * * @param f A transformation from this tree's elements, to the monoid. * @param m The monoid to fold this tree with. * @return The result of folding the tree with the given monoid. */ public <B> B foldMap(final F<A, B> f, final Monoid<B> m) { return m.sum(f.f(root()), m.sumRight(subForest()._1().map(foldMap_(f, m)).toList())); }
@Theory public void sumBinOp(Integer x, Integer y) { Integer actual = sumMonoid.multiply(x, y); assertThat(actual, is(x + y)); }
@Test public void sumUnitIsZero() { assertThat(sumMonoid.unit(), is(0)); }