Created
October 5, 2021 15:39
-
-
Save DevSrSouza/c717ab0719f9d76c040fa356943f7d31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Either<out L, out R> { | |
class Left<L>(val value: L) : Either<L, Nothing>() | |
class Right<R>(val value: R) : Either<Nothing, R>() | |
fun fold( | |
onLeft: (L) -> Unit, | |
onRight: (R) -> Unit, | |
) { | |
when(this) { | |
is Left -> onLeft(value) | |
is Right -> onRight(value) | |
} | |
} | |
} | |
fun <R> right(value: R): Either<Nothing, R> = Either.Right(value) | |
fun <L> left(value: L): Either<L, Nothing> = Either.Left(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment