Skip to content

Instantly share code, notes, and snippets.

@jsh-me
Created January 17, 2021 07:06
Show Gist options
  • Save jsh-me/3a20f564275f0644449e709e400fae13 to your computer and use it in GitHub Desktop.
Save jsh-me/3a20f564275f0644449e709e400fae13 to your computer and use it in GitHub Desktop.
Wrap Callbacks as Coroutines in Android
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