Skip to content

Instantly share code, notes, and snippets.

@fabioCollini
Created September 19, 2021 17:14
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 fabioCollini/2420cf584e7c99432f75ebf9e0e70eb4 to your computer and use it in GitHub Desktop.
Save fabioCollini/2420cf584e7c99432f75ebf9e0e70eb4 to your computer and use it in GitHub Desktop.
class CalculatorViewModel : ViewModel() {
var v1 by mutableStateOf("0")
var v2 by mutableStateOf("0")
var result by mutableStateOf("0")
private set
init {
snapshotFlow { v1 to v2 }
.mapLatest {
sum(it.first, it.second)
}
.onEach {
result = it
}
.launchIn(viewModelScope)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment