Skip to content

Instantly share code, notes, and snippets.

@fabioCollini
Created September 19, 2021 17:10
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/edc93f6b89d75981f4cd47262d14c590 to your computer and use it in GitHub Desktop.
Save fabioCollini/edc93f6b89d75981f4cd47262d14c590 to your computer and use it in GitHub Desktop.
class CalculatorViewModel : ViewModel() {
var v1 = MutableStateFlow("0")
var v2 = MutableStateFlow("0")
val result = v1.combine(v2) { a, b -> a to b}.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