Alex
08/31/2021, 10:39 AM.map
a StateFlow
and have it still be a StateFlow
? Why the conversion to a regular Flow
?CLOVIS
08/31/2021, 10:49 AM.map
can suspend, the child flow needs its own scope. You can convert a flow into a StateFlow with .stateIn
.Chris Fillmore
09/01/2021, 1:00 AMval numberFlow = MutableStateFlow<Int>(0)
val lessThanZero = numberFlow.filter { it < 0 }
// Suppose for a moment that filter/map could return a StateFlow, how would the below work:
val currentValue = lessThanZero.value
// What's the value of currentValue?
Alex
09/01/2021, 8:11 AM.filter
this is easy, but for map
its harder to see, since map will always return a value. map
being able to suspend solves the question because then it might suspend for a while (on first submision) in which no value is present in the resulting stateflow, which is not allowed.