Created
January 17, 2021 07:06
-
-
Save jsh-me/3a20f564275f0644449e709e400fae13 to your computer and use it in GitHub Desktop.
Wrap Callbacks as Coroutines in Android
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 Result<out R> { | |
data class Success<out T>(val data: T) : Result<T>() | |
data class Error(val exception: Exception) : Result<Nothing>() | |
} | |
fun <T>Result<T>.getValue(): T { | |
return if(this is Result.Success) { | |
this.data | |
} else { | |
throw (this as Result.Error).exception | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment