Nacho Ruiz Martin
01/02/2022, 2:34 PMStateFlow
and still have a StateFlow
and not a Flow
?
stateflow.map(::mapper)
returns a Flow
.Joffrey
01/02/2022, 2:36 PMStateFlow
you would need to store a new state and to have a coroutine that collects the source flow into the new one. You could use stateIn after map
to do that for you behind the scenes.Nacho Ruiz Martin
01/02/2022, 2:37 PMJoffrey
01/02/2022, 2:37 PMStateFlow
as a result there (why is Flow
not sufficient)?Nacho Ruiz Martin
01/02/2022, 2:41 PMStateFlow
just to have better integration with Jetpack Compose.
In Rx
a simple map
on a BehaviourSubject
would suffice, if I’m not mistaken.streetsofboston
01/02/2022, 2:49 PMmap
method on BehaviorSubject
is a plain Observable
(which is comparable to a plain Flow
), which gives you the same type of problem that you are asking about.
http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/subjects/BehaviorSubject.htmlNacho Ruiz Martin
01/02/2022, 2:49 PMMartin Rajniak
01/02/2022, 2:58 PMAdam Powell
01/02/2022, 4:18 PMAdam Powell
01/02/2022, 4:19 PMAdam Powell
01/02/2022, 4:20 PMNacho Ruiz Martin
01/02/2022, 5:50 PMstateIn
. Feels a bit weird, but it works.hfhbd
01/02/2022, 10:51 PM(Mutable) State
is nice, the advantage using StateFlow
is multiplatform support, especially iOS.