Luke
11/07/2020, 7:38 PMStateFlow<T>
to a StateFlow<R>
? I have a MutableStateFlow<MyEnum>
in a view model, but I want it private to expose publicly a StateFlow<String>
Javier
11/07/2020, 7:39 PM.map
?Luke
11/07/2020, 7:40 PMFlow
, not a StateFlow
Javier
11/07/2020, 7:42 PMLuke
11/07/2020, 7:50 PMstateIn
is a `suspend fun`… So I can’t assign my variable directly like a simple map would allowstateIn
are suspend fun
streetsofboston
11/07/2020, 8:03 PMStateFlow<R>
, how would the map
function reverse map the latest value from a T
to an R
, when assigning a new value to that StateFlow<R>
if it were implemented by a MutableStateFlow?
And this is just for map
.
How would this work for filter
? Etc..
Using stateIn helps by layering another statefull flow on top of the returned Flowrnett
11/07/2020, 10:08 PMMutableStateFlow
would need to go backwards, but I don't see a reason why you couldn't map a StateFlow
backed by a MutableStateFlow
into something like a ReadOnlyStateFlow
.gildor
11/08/2020, 11:26 PMrnett
11/09/2020, 12:47 AMStateFlow
is MutableStateFlow
(or rather StateFlowImpl
, which stores a value). For map support, you would need a new implementation that doesn't store it's own state or support updates. But I think it would be exposed as just StateFlow
, yeah.gildor
11/09/2020, 4:33 AMrnett
11/09/2020, 5:35 AMgildor
11/09/2020, 5:53 AM