Mark
10/21/2020, 1:08 PMFlow.combine(Flow)
However, the second flow is not known until at some point in the progression of the original Flow (at which point, the second flow can be derived). At the moment, I achieve this by (and it feels like a very nasty hack) having a MutableStateFlow
and updating that flow from a coroutine launched from within onEach
(just before combine
). So then we use combine(MutableStateFlow)
. But how to do this properly?louiscad
10/21/2020, 1:20 PMonStart { emit(initialValue) }
?Mark
10/21/2020, 1:24 PMcombine
to take a Flow that is derived from the current value of the main Flowlouiscad
10/21/2020, 1:25 PMinitialValue
to be null
or something that you can distinguish from the combine
lambda.Marc Knaup
10/21/2020, 1:26 PMMark
10/21/2020, 1:28 PMMark
10/21/2020, 1:28 PMMarc Knaup
10/21/2020, 1:30 PMMark
10/21/2020, 1:31 PMMarc Knaup
10/21/2020, 1:34 PMephemient
10/21/2020, 1:35 PM.flatMapLatest()
from your description but it's hard to tellMarc Knaup
10/21/2020, 1:35 PMFlow<Item>
and one Deferred<Flow<Item>>
(kinda)?
I still can’t wrap my head around it 😄Mark
10/21/2020, 1:38 PMFlow<List<Item>>
and then for a certain Item
subclass, I can create a Flow<DynamicStuffForSpecialItem>
and then I can Flow<List<Item>>.combine(Flow<DynamicStuffForSpecialItem>>)
to make Flow<List<Item>>
Mark
10/21/2020, 1:39 PMFlow
has a dynamic item in place of the special static item in the original flowMarc Knaup
10/21/2020, 1:43 PMMarc Knaup
10/21/2020, 1:43 PMMark
10/21/2020, 1:44 PMMarc Knaup
10/21/2020, 1:45 PMFlow<List<Item>>
is already being used, right?Mark
10/21/2020, 1:45 PMlouiscad
10/21/2020, 1:46 PMcombine
, and also use onStart
if needed?Marc Knaup
10/21/2020, 1:46 PMFlow<DynamicStuffForSpecialItem?>
instead that either emits null
(no dynamic stuff available) or DynamicStuffForSpecialItem
.Mark
10/21/2020, 1:54 PMMutableStateFlow
of Flow<DynamicStuffForSpecialItem?>
and then pass the flatMapLatest { it ?: flowOf(nothing) }
to combine
(thanks for the tip @ephemient). The MutableStateFlow
is set in onEach
when the dynamic flow becomes available. Is this the best way?Marc Knaup
10/21/2020, 1:56 PMStateFlow
, flatMapLatest
and onEach
😅Mark
10/22/2020, 1:47 AMFlow
whose purpose is to act as a kind of container to receive a delayed Flow
(and then to be used with flatMapLatest
)?louiscad
10/22/2020, 5:57 AMMark
10/22/2020, 6:02 AMflorent
10/22/2020, 8:18 AMephemient
10/22/2020, 8:46 AMephemient
10/22/2020, 8:46 AMMark
10/23/2020, 3:39 AMstateInWithTermination
? From what I can see, it’s just duplicating a Flow and re-emitting the last value? What am I missing?ephemient
10/23/2020, 7:08 AM.collect()
would continue forever if I used .stateIn()
directly. .stateInWithTermination()
returns a flow which behaves like .stateIn()
until the underlying flow completes, after which it behaves like flowOf(final value)
.Mark
10/23/2020, 9:41 AMephemient
10/23/2020, 9:53 AMval flow = ...
launch { flow.collect { println("1: $it") } }
launch { flow.collect { println("2: $it") } }
ephemient
10/23/2020, 9:55 AMMark
10/23/2020, 9:55 AMMark
10/23/2020, 9:57 AMephemient
10/23/2020, 9:58 AM