Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Emulated Sum Type in Java as described by Lukas Eder and Daniel Dietrich
import java.math.BigInteger;
import java.util.function.Consumer;
public class EmulatedSumType {
static class Tuple3<T1, T2, T3> {
final T1 v1;
final T2 v2;
final T3 v3;
public Tuple3(T1 t1, T2 t2, T3 t3) {
v1 = t1;
v2 = t2;
v3 = t3;
// Lots of useful stuff here
static <T, T1 extends T, T2 extends T, T3 extends T> void forEach(Tuple3<T1, T2, T3> tuple,
Consumer<? super T> consumer) {
public static void main(final String[] bla) {
Tuple3<BigInteger, Long, Integer> tuple3 = new Tuple3<BigInteger, Long, Integer>(BigInteger.TEN, 1L, 3);
forEach(tuple3, v -> System.out.println(v.doubleValue()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment