Hi, beginner flow user here, please what operator ...
# flow
s
Hi, beginner flow user here, please what operator do I need to conditionally run a flow
flow2
based on the condition of an upstream flow
flow1
? this is what I have tried but I am not sure if I actually should be doing the tagged line
Copy code
flow1()
 .flatMapLatest { res ->
   if(res.conditionIsFalse) {
     flowOf() // works but wondering if there is an operator that doesn't require this
   } else {
     flow2()
   }
 }
 .onEach { flow2Res -> 
   // do something with flow2Res
 }
 .launchIn(scope)
w
flatMapLatest
is pretty much what you want, you can use
emptyFlow()
to not emit anything.
s
thanks @wasyl, looks like what I am doing works then.
w
Be aware of the difference between
flatMapMerge
,
flatMapConcat
and `flatMapLatest`: the first one will run multiple inner flows simultaneously and emit their values as they come,
concat
version will also run inner flows but maintain order in which they were triggered (so concat their emissions), and
latest
one will cancel the previous inner flow once the new item is handled
👍 2
s
makes sense @wasyl, thanks a lot. I am just understanding what the
flatMapMerge
doc means for the first time with your explanation 😅
👍 1