Sealed Class Example
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 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