Skip to content

Instantly share code, notes, and snippets.

@happy-bracket
Created December 25, 2019 12:55
Show Gist options
  • Save happy-bracket/dbcc91e6dd6afd0fda1fd3b28360b9d5 to your computer and use it in GitHub Desktop.
Save happy-bracket/dbcc91e6dd6afd0fda1fd3b28360b9d5 to your computer and use it in GitHub Desktop.
EitherN, but beter
sealed class Either2<A, B> {
data class Op1<A>(val value: A) : Either2<A, Nothing>()
data class Op2<B>(val value: B) : Either2<Nothing, B>()
}
sealed class Either3<A, B, C> : Either2<A, B>() {
data class Op3<C>(val value: C) : Either3<Nothing, Nothing, C>()
}
sealed class Either4<A, B, C, D> : Either3<A, B, C>() {
data class Op4<D>(val value: D) : Either4<Nothing, Nothing, Nothing, D>()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment