-
-
Save PatilShreyas/5b0977b3d49821ce49d64f1dabbf7890 to your computer and use it in GitHub Desktop.
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 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