Skip to content

Instantly share code, notes, and snippets.

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