Created
June 21, 2019 22:26
-
-
Save ShelbyCohen/b11e3577e1efa0a845a2ac7cd93685a5 to your computer and use it in GitHub Desktop.
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