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 org.jetbrains.annotations.NotNull;
public final class FreePairingMonoid implements Monoid> {
@NotNull
private final Monoid monoidA;
@NotNull
private final Monoid monoidB;
public FreePairingMonoid(@NotNull Monoid monoidA, @NotNull Monoid monoidB) {
this.monoidA = monoidA;
this.monoidB = monoidB;
}
@NotNull
@Override
public Pair identity() {
return new Pair<>(this.monoidA.identity(), this.monoidB.identity());
}
@NotNull
@Override
public Pair append(Pair a, Pair b) {
return new Pair<>(monoidA.append(a.a, b.a), monoidB.append(a.b, b.b));
}
}