Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created December 29, 2020 11:16
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 PatilShreyas/14471ba306c20f2a9a40bb950d27da9c to your computer and use it in GitHub Desktop.
Save PatilShreyas/14471ba306c20f2a9a40bb950d27da9c to your computer and use it in GitHub Desktop.
class Success(val result: Any)
class Failure(val message: String)
fun main() {
val result = getResult()
val something = when (result) {
is Success -> {}
is Failure -> {}
else -> { /* Unnecessary part */ }
}
}
fun getResult() = listOf(Success(""), Failure("Failed")).random()
sealed class Result {
class Success(val result: Any): Result()
class Failure(val message: String): Result()
}
fun main() {
val result = getResult()
val something = when (result) {
is Result.Success -> {}
is Result.Failure -> {}
}
}
fun getResult(): Result = listOf(Result.Success(""), Result.Failure("Failed")).random()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment