John Aoussou
12/17/2021, 3:04 PMprivate val _stateFlow1 = MutableStateFlow(0)
Is there a way to define _stateFlow2
so that _stateFlow2.value = _stateFlow1.value * _stateFlow1.value
?Stew Boling
12/17/2021, 3:29 PMval _stateFlow1 = MutableStateFlow(0)
val _stateFlow2 = _stateFlow1.map { it * it }.stateIn(viewModelScope)
That is if you need _stateFlow2 to be a StateFlow otherwise you can drop stateIn()
John Aoussou
12/17/2021, 3:42 PMStew Boling
12/17/2021, 3:43 PMJohn Aoussou
12/17/2021, 3:44 PMSuspend function 'stateIn' should be called only from a coroutine or another suspend function
Stew Boling
12/17/2021, 3:46 PMstateIn()
there is a non-suspending one
val _stateFlow1 = MutableStateFlow(0)
val _stateFlow2 = _stateFlow1.map { it * it }.stateIn(viewModelScope, SharingStarted.Eagerly, _stateFlow1.value)
John Aoussou
12/17/2021, 3:50 PM