https://kotlinlang.org logo
#flow
Title
# flow
a

alexfacciorusso

07/26/2021, 8:45 AM
Hey all! I have been thinkering on this problem for a bit, and I think there’s something I might be missing. I have a data class, MyThing1, which has an ID in it. data class
MyThing1(val id: String)
I have another data class which we don’t care about its content, but let’s call it
MyThing2
I have a Flow, that returns a list of MyThing1
fun myEmitter1(): Flow<List<MyThing1>>
I have another Flow that takes in input an ID and returns a flow of objects, so
fun myEmitter2(id: String): Flow<MyThing2>
For each MyThing1 received from the flow, I want to combine it with the latest MyThing2 that gets emitted by
myEmitter2
and return a
Flow<List<CombinedThing>>
given the CombinedThing is
data class CombinedThing(val myThing1: MyThing1, val myThing2: MyThing2)
. Any thought for doing it efficiently?
n

Nick Allen

08/02/2021, 10:45 PM
Copy code
myEmitter.flatMapLatest { myThing1 ->
    myEmitter2(myThing1.id).map { CombinedThing(myThing1, it}
}
2 Views