Skip to content

Instantly share code, notes, and snippets.

@jbgi
Created March 10, 2016 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbgi/a411f1d04713fcadbcc9 to your computer and use it in GitHub Desktop.
Save jbgi/a411f1d04713fcadbcc9 to your computer and use it in GitHub Desktop.
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