Skip to content

Instantly share code, notes, and snippets.

@ericntd
Last active September 9, 2021 17:04
Show Gist options
  • Save ericntd/8109ccdf4054b9ea332fccf5bafb87b1 to your computer and use it in GitHub Desktop.
Save ericntd/8109ccdf4054b9ea332fccf5bafb87b1 to your computer and use it in GitHub Desktop.
class SomeViewModel(val inputStream: Observable<SomeDataType>, ...) {
private val viewState = MutableLiveData<ViewState>()
init {
doStep1()
//...
.doStepK()
.zipWith(inputStream) // combine/ merge 2 streams into 1 using Pair
.map { pair ->
val stepKresult = pair.first
val input = pair.second // data from button click
someUsefulVariable = ... // derived from stepKresult and button click data
return@map processData(stepKResult, someUsefulVariable)
}
.handleResult { finalResult -> viewState.value = ViewState.DataLoaded(...) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment