Created
April 22, 2020 20:54
-
-
Save cdmunoz/523ab2a69fa679eddacc100319231297 to your computer and use it in GitHub Desktop.
Generic Result sealed class to UI state management for a network result
This file contains hidden or 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 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