Skip to content

Instantly share code, notes, and snippets.

@1gravity
Last active March 23, 2022 17:35
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 1gravity/0d3cfd9cad694d349b127e115ea2d1b6 to your computer and use it in GitHub Desktop.
Save 1gravity/0d3cfd9cad694d349b127e115ea2d1b6 to your computer and use it in GitHub Desktop.
Imperative Kotlin Example
when (val postData = networkDataSource.getPost(id)) {
is Status.Success -> {
val comments = async {
networkDataSource.getComments().filter { it.postId == postData.data.id }
}
Status.Success(
PostDetail(
postData.data.id,
postData.data.body,
comments.await().map { PostComment(it.id, it.name, it.email, it.body) }
)
)
}
is Status.Failure -> Status.Failure(postData.exception)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment