https://kotlinlang.org logo
#coroutines
Title
# coroutines
o

Orhan Tozan

05/10/2020, 5:16 PM
How do I map a
StateFlow
to another
StateFlow
?
stateFlow.map { } as StateFlow<T>
throws a ClassCastException
r

rkeazor

05/10/2020, 5:57 PM
There is a example in the kDoc of how to combine 2 stateFlow
o

Orhan Tozan

05/10/2020, 5:58 PM
The combine is returning a Flow though, instead of a StateFlow
r

rkeazor

05/10/2020, 6:01 PM
But wouldn't that be all you need?
that way you can collect from it
o

Orhan Tozan

05/10/2020, 6:01 PM
Not really, the mapped flow still represents a state
Of course you can still collect from it, but can't access the flow's value at any time
r

rkeazor

05/10/2020, 6:02 PM
yea that would be the only thing missing. I see what you mean
o

Orhan Tozan

05/10/2020, 6:04 PM
515 Views