com.shapesecurity.functional.data.FreePairingMonoid Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shape-functional-java Show documentation
Show all versions of shape-functional-java Show documentation
Functional programming library
package com.shapesecurity.functional.data;
import com.shapesecurity.functional.Pair;
import javax.annotation.Nonnull;
public final class FreePairingMonoid implements Monoid> {
@Nonnull
private final Monoid monoidA;
@Nonnull
private final Monoid monoidB;
public FreePairingMonoid(@Nonnull Monoid monoidA, @Nonnull Monoid monoidB) {
this.monoidA = monoidA;
this.monoidB = monoidB;
}
@Nonnull
@Override
public Pair identity() {
return new Pair<>(this.monoidA.identity(), this.monoidB.identity());
}
@Nonnull
@Override
public Pair append(Pair a, Pair b) {
return new Pair<>(this.monoidA.append(a.left, b.left), this.monoidB.append(a.right, b.right));
}
}