Skip to content

Instantly share code, notes, and snippets.

@jbrunton
Last active November 28, 2018 00:06
Show Gist options
  • Save jbrunton/291f96890a24c4fb079bb85d39e5b684 to your computer and use it in GitHub Desktop.
Save jbrunton/291f96890a24c4fb079bb85d39e5b684 to your computer and use it in GitHub Desktop.
AsyncResult Simple Example
val result: AsyncResult<MyData> = // ...
val viewState = result
.map { MyViewState.from(it) }
.onError(IOException::class) {
map {
if (cachedValue == null) {
failure(NoConnectionViewState)
} else {
success(cachedValue)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment