11package fj ;
22
33import static fj .Function .curry ;
4- import static fj .Function .compose ;
54import static fj .Function .flip ;
65import fj .data .Array ;
76import fj .data .List ;
2019 * <ul>
2120 * <li><em>Left Identity</em>; forall x. sum(zero(), x) == x</li>
2221 * <li><em>Right Identity</em>; forall x. sum(x, zero()) == x</li>
23- * <li><em>Associativity</em>; forall x. forall y. forall z. sum(sum(x, y), z) == sum(x, sum(y, z))</li>
22+ * <li><em>Associativity</em>; forall x y z. sum(sum(x, y), z) == sum(x, sum(y, z))</li>
2423 * </ul>
2524 *
2625 * @version %build.number%
@@ -34,6 +33,14 @@ private Monoid(final F<A, F<A, A>> sum, final A zero) {
3433 this .zero = zero ;
3534 }
3635
36+ /**
37+ * Composes this monoid with another.
38+ */
39+ public <B > Monoid <P2 <A ,B >>compose (Monoid <B > m ) {
40+ return monoid ((P2 <A ,B > x ) -> (P2 <A ,B > y ) ->
41+ P .p (sum (x ._1 (), y ._1 ()), m .sum (x ._2 (), y ._2 ())), P .p (zero , m .zero ));
42+ }
43+
3744 /**
3845 * Returns a semigroup projection of this monoid.
3946 *
@@ -176,7 +183,7 @@ public A join(final Iterable<A> as, final A a) {
176183 final Stream <A > s = iterableStream (as );
177184 return s .isEmpty () ?
178185 zero :
179- s .foldLeft1 (compose (sum , flip (sum ).f (a )));
186+ s .foldLeft1 (Function . compose (sum , flip (sum ).f (a )));
180187 }
181188
182189 /**
0 commit comments