https://kotlinlang.org logo
Title
t

Tiago Nunes

06/14/2021, 2:12 PM
Hi everyone, how do I convert a
List<Flow<T>>
to a
Flow<List<T>>
? Sounds simple enough but it's bugging my brain 😅
w

wasyl

06/14/2021, 2:15 PM
combine
?
👍 2
j

Joffrey

06/14/2021, 2:15 PM
I think it depends on what you want to happen. There is the combine function that you can use, but it might not be the behaviour you expect:
combine(flows) { mostRecentValuesInEach -> 
    mostRecentValuesInEach.toList()
}
👍 1
t

Tiago Nunes

06/14/2021, 2:16 PM
Yep, thats it, thanks guys 🎉
j

Joffrey

06/14/2021, 2:17 PM
Note that this will emit a new list each time one of the flows has a new value, thus re-emitting the last element of all other flows. Is that what you want?
t

Tiago Nunes

06/14/2021, 2:17 PM
Yep!
👌 1