Created
April 15, 2018 20:37
-
-
Save monday8am/02cc2ae467845e1ef8ecacfaa56bcca9 to your computer and use it in GitHub Desktop.
Result variant of Either pattern
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 Result <out V, out E> { | |
// Idle state | |
object Loading : Result<Nothing, Nothing>() | |
// Operation finished correctly with result saved on value | |
data class Ok <out V > constructor (val value: V): Result<V, Nothing>() | |
// Operation finished with error | |
data class Err <out E> constructor (val error: E): Result<Nothing, E>() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment