Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active December 29, 2020 11:30
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 PatilShreyas/5b0977b3d49821ce49d64f1dabbf7890 to your computer and use it in GitHub Desktop.
Save PatilShreyas/5b0977b3d49821ce49d64f1dabbf7890 to your computer and use it in GitHub Desktop.
sealed class ViewState {
object Loading: ViewState()
class Success(val someData: String): ViewState()
class Failure(val message: String): ViewState()
}
fun main() {
val message = when (getViewState()) {
is ViewState.Loading -> "Data is loading"
is ViewState.Success -> "Got data: ${state.someData}"
is ViewState.Failure -> "It failed! ${state.message}"
}
println(message)
}
fun getViewState(): ViewState = listOf(ViewState.Loading, ViewState.Success("MyData"), ViewState.Failure("Error")).random()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment