https://kotlinlang.org logo
Title
a

adte

04/08/2023, 2:20 AM
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

Francesc

04/08/2023, 2:25 AM
flatMapLatest
generates a new flow for each emission of the original flow, is that what you want?
a

adte

04/08/2023, 2:31 AM
@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

Francesc

04/08/2023, 2:50 AM
Do you want the first flow first value only, or do you want to observe all emissions of the first flow?
a

adte

04/08/2023, 2:52 AM
All emissions yeah
f

Francesc

04/08/2023, 2:53 AM
And you want one further emission from each or multiple?
a

adte

04/08/2023, 2:54 AM
I want both flows to keep emitting
f

Francesc

04/08/2023, 2:54 AM
How are their outputs related?
i.e what do you want as result
a

adte

04/08/2023, 2:55 AM
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

Francesc

04/08/2023, 2:56 AM
That sounds like flatMapLatest, for each row ID emission you emit a set of items belonging to that row
a

adte

04/08/2023, 3:00 AM
@Francesc Thanks for confirming. all these functions get quite confusing 🙂
p

Patrick Steiger

04/08/2023, 1:58 PM
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