is there a function in the coroutines lib that tra...
# coroutines
s
is there a function in the coroutines lib that transforms a
List<Flow<T>>
to
Flow<List<T>>
?
I have a list of ids -
List<Long>
for each ID I'm calling Room, which returns a
Flow<T>
so by doing
list.map { db.getItem(it) }
I get
List<Flow<T>>
e
Copy code
combine(flows) { it.toList() }
👍 2
h
depends on you your usecase: How do you want to merge the flows?
e
that being said, maybe you should change your room query to accept a list of IDs?
s
I think
combine
is what I was looking for.... somehow I missed combine that accepts a
List
thanks 🙏
e
e.g.
Copy code
@Query("SELECT * FROM table WHERE id IN (:ids)")
fun getByIds(ids: List<Long>): Flow<List<Model>>
👍 3
less sqlite IO and less post-processing work
s
list is up to 5 elements, so I think it's fine in code... but thanks for the tip