Skip to content

Instantly share code, notes, and snippets.

@vlazzle
Created February 16, 2018 00:15
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 vlazzle/f35089048c0920ce11e574e9e0266000 to your computer and use it in GitHub Desktop.
Save vlazzle/f35089048c0920ce11e574e9e0266000 to your computer and use it in GitHub Desktop.
sealed class Either<L, R> {
class Left<L1, R1>(val left: L1) : Either<L1, R1>()
class Right<L1, R1>(val right: R1) : Either<L1, R1>()
}
val left: Either<String, Throwable> = Either.Left("foo")
val right: Either<String, Throwable> = Either.Right(Throwable("bar"))
val leftOrRight = left
val x: String = when (leftOrRight) {
is Either.Left -> leftOrRight.left
// is Either.Right -> leftOrRight.right.message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment