Skip to content

Instantly share code, notes, and snippets.

@kiratheone
Forked from cdmunoz/Result.kt
Created June 22, 2021 05:32
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 kiratheone/a452054a88511a3052466abb0bc41328 to your computer and use it in GitHub Desktop.
Save kiratheone/a452054a88511a3052466abb0bc41328 to your computer and use it in GitHub Desktop.
Generic Result sealed class to UI state management for a network result
sealed class Result<out T : Any> {
data class Success<out T : Any>(val data: T) : Result<T>()
data class Error(val exception: Exception) : Result<Nothing>()
object InProgress : Result<Nothing>()
val extractData: T?
get() = when (this) {
is Success -> data
is Error -> null
is InProgress -> null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment