Created
October 18, 2015 21:05
-
-
Save techtangents/b71a6512e8ca31b9266a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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