Skip to content

Instantly share code, notes, and snippets.

@monday8am
Created April 15, 2018 20:37
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 monday8am/02cc2ae467845e1ef8ecacfaa56bcca9 to your computer and use it in GitHub Desktop.
Save monday8am/02cc2ae467845e1ef8ecacfaa56bcca9 to your computer and use it in GitHub Desktop.
Result variant of Either pattern
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