Skip to content

Instantly share code, notes, and snippets.

@nomisRev
Created July 9, 2017 18:51
Show Gist options
  • Save nomisRev/ab9f3be7eb43a3876359781244ad2a6e to your computer and use it in GitHub Desktop.
Save nomisRev/ab9f3be7eb43a3876359781244ad2a6e to your computer and use it in GitHub Desktop.
sealed class Result {
fun flatMap(f: (Int) -> Result): Result = when(this) {
is Success -> f(value)
is Failure -> this
}
fun map(f: (Int) -> Int): Result = when(this) {
is Success -> Success(f(value))
is Failure -> this
}
}
data class Success(val value: Int) : Result()
data class Failure(val message: String) : Result()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment