Either<A, B> left(A a) { new Left<>(a); } public static <A, B> Either<A, B> right(B b) { new Right<>(b); } public abstract boolean isLeft(); public abstract boolean isRight(); public abstract <X> X fold(Fold<A, X> l, Fold<B, X> r); } &JUIFSKBWB
Either<A, B>() { override val isLeft: Boolean = true override val isRight: Boolean = false } data class Right<out A, out B>(val value: B) : Either<A, B>() { override val isLeft: Boolean = false override val isRight: Boolean = true }