Created
March 10, 2016 14:20
-
-
Save jbgi/a411f1d04713fcadbcc9 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.function.Function; | |
import org.derive4j.Data; | |
class Y{} | |
class Z{} | |
@Data | |
public abstract class X<YZ> { | |
X(){} | |
interface Cases<YZ, R> { | |
R y(Y y, Function<Y, YZ> id); | |
R z(Z z, Function<Z, YZ> id); | |
} | |
public abstract <R> R match(Cases<YZ, R> cases); | |
public static void main(String[] args) { | |
// type variable of X<YZ> is constrained to be either of: | |
X<Y> xy = Xs.y(new Y()); | |
X<Z> xz = Xs.z(new Z()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment