Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sealed Class Example
sealed class UserResult {
data class Failure(val message : String) : UserResult()
data class Success(val users : List<String>) : UserResult()
data class Loading(val animation : String) : UserResult()
}
fun process(result : UserResult) = when(result) {
is UserResult.Failure -> println(result.message)
is UserResult.Success -> result.users.forEach { println(it)}
is UserResult.Loading -> println(result.animation)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.