Skip to content

Instantly share code, notes, and snippets.

@OssamaDroid
Last active February 10, 2020 00:29
Show Gist options
  • Save OssamaDroid/aee64ce9b290dfdb2d5823d2afb95f81 to your computer and use it in GitHub Desktop.
Save OssamaDroid/aee64ce9b290dfdb2d5823d2afb95f81 to your computer and use it in GitHub Desktop.
// Result class of the SubmitName action
sealed class Result {
sealed class SubmitResult : Result() {
object Success: SubmitResult()
object InFlight: SubmitResult()
data class Failure(val errorMessage: String): SubmitResult()
}
}
private val submitName: ObservableTransformer<SubmitNameAction, SubmitResult> =
ObservableTransformer { actions ->
actions.flatMap { event ->
repository.sendName(event.name) // The asynchronous call
.andThen(Observable.just(SubmitResult.Success as SubmitResult))
.onErrorReturn { SubmitResult.Failure(it.message ?: "Your error message") }
.observeOn(AndroidSchedulers.mainThread())
.startWith(SubmitResult.InFlight)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment