Skip to content

Instantly share code, notes, and snippets.

@fabioCollini
Created September 19, 2021 17:13
Show Gist options
  • Save fabioCollini/1b1aa405c0ac2fe0d05eaed2ab31491b to your computer and use it in GitHub Desktop.
Save fabioCollini/1b1aa405c0ac2fe0d05eaed2ab31491b to your computer and use it in GitHub Desktop.
class CalculatorViewModel : ViewModel() {
var v1 by mutableStateOf("0")
var v2 by mutableStateOf("0")
val result = snapshotFlow { v1 to v2 }.mapLatest {
sum(it.first, it.second)
}.stateIn(viewModelScope, SharingStarted.Lazily, "0")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment