Arjan van Wieringen
12/19/2022, 4:22 PMFlow<List<Foo>> where Foo also contains a Flow
• interface Foo { val name: String; val flow: Flow<Long> }
How can I transform Flow<List<Foo> to something like Flow<List<Pair<String, Long>>> where the pair is based on the name anf the inner flow value?Sam
12/19/2022, 4:24 PMflatMapArjan van Wieringen
12/19/2022, 4:24 PMArjan van Wieringen
12/19/2022, 4:24 PMArjan van Wieringen
12/19/2022, 4:25 PMSam
12/19/2022, 4:26 PMflatMapMerge and flatMapConcat. Which one you want is going to depend on your specific case.Arjan van Wieringen
12/19/2022, 4:27 PMSam
12/19/2022, 4:27 PMArjan van Wieringen
12/19/2022, 4:28 PMSam
12/19/2022, 4:33 PMFoo, or should it emit a new value each time Foo.flow emits? 🤔Arjan van Wieringen
12/19/2022, 4:35 PMSam
12/19/2022, 4:39 PMFlow<List<Foo>> emits a new list, should that replace all of the previous Foo flows?Arjan van Wieringen
12/19/2022, 4:42 PMval state = fooListFlow.flatMapLatest { fooFlows: List<Foo> ->
combine(
fooFlows.map { foo: Foo ->
foo.flow.map { inner: Long ->
Pair(foo.name, inner)
}
}
) {
it.toList()
}Arjan van Wieringen
12/19/2022, 4:42 PMSam
12/19/2022, 4:44 PMArjan van Wieringen
12/19/2022, 4:45 PMSam
12/19/2022, 4:50 PMSam
12/19/2022, 4:52 PMflatMapLatest will stop collecting the existing flows each time it gets new ones, but flatMapMerge and flatMapConcat will just keep on collecting all of them them until they terminate.Arjan van Wieringen
12/19/2022, 4:52 PM