If I want to create a Flow that need the value of ...
# coroutines
a
If I want to create a Flow that need the value of another Flow as input parameter, is
flatMapLatest
the function I should be using?
f
flatMapLatest
generates a new flow for each emission of the original flow, is that what you want?
a
@Francesc No, I don't think so. Should I just use
map
then?
I don't want map, because I end up with a Flow<Flow<T>>. I want to use the latest value of the input flow to generate a new flow
I guess I'm looking at
flatMapConcat
then
f
Do you want the first flow first value only, or do you want to observe all emissions of the first flow?
a
All emissions yeah
f
And you want one further emission from each or multiple?
a
I want both flows to keep emitting
f
How are their outputs related?
i.e what do you want as result
a
Each flow I'm querying a table, but the first flow value has the row id that I need to do the second query
f
That sounds like flatMapLatest, for each row ID emission you emit a set of items belonging to that row
a
@Francesc Thanks for confirming. all these functions get quite confusing 🙂
p
flatMapLatest
- aborts inner flow when new value from outer flow arrives
flatMapConcat
- waits for inner flow to finish (emits all value from it) before processing new values from outer flow
flatMapMerge
- for each new value from outer flow, emits all value from inner flows concurrently