Skip to content

Instantly share code, notes, and snippets.

@zarinfam
Created June 25, 2019 09:14
Show Gist options
  • Save zarinfam/a56a02f3169375aa57ac97a71039c264 to your computer and use it in GitHub Desktop.
Save zarinfam/a56a02f3169375aa57ac97a71039c264 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
interface Monoid<A> extends Empty<A> {
A combine(A x, A y);
...
static <A, B> Monoid<Pair<A, B>> deriveMonoidPair(Monoid<A> A, Monoid<B> B) {
return new Monoid<>() {
@Override
public Pair<A, B> combine(Pair<A, B> x, Pair<A, B> y) {
return new Pair<>(A.combine(x.getFirst(), y.getFirst()), B.combine(x.getSecond(), y.getSecond()));
}
@Override
public Pair<A, B> empty() {
return new Pair<>(A.empty(), B.empty());
}
};
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment