Skip to content

Instantly share code, notes, and snippets.

@techtangents
Created October 18, 2015 21:05
Show Gist options
  • Save techtangents/b71a6512e8ca31b9266a to your computer and use it in GitHub Desktop.
Save techtangents/b71a6512e8ca31b9266a to your computer and use it in GitHub Desktop.
package com.example;
public abstract class Either<A, B> {
public abstract <T> T fold(final F<A, T> af, final F<B, T> bf);
private Either(){}
public static <A, B> Either<A, B> a(final A a) {
return new Either<A, B>() {
@Override
public <T> T fold(final F<A, T> af, final F<B, T> bf) {
return af.apply(a);
}
};
}
public static <A, B> Either<A, B> b(final B b) {
return new Either<A, B>() {
@Override
public <T> T fold(final F<A, T> af, final F<B, T> bf) {
return bf.apply(b);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment