What is the proper way to listen to multiples flow...
# coroutines
t
What is the proper way to listen to multiples flows of any possible type and have a resulting flow whose only purpose is to do something but does not care about the value, just that one of the flow have changed? Like I have 10
Copy code
flowX.drop(1)
And would like to have a function that collect them all in a scope and call 1 function when any value is received (would be nice it the result was a flow so I can debounce too) So some kind of combine but without types and transform and supporting any number of input flows.
j
Can't you just use combine and ignore the values? There is an overload that takes a vararg of any number of flows:
Copy code
combine(flow1, flow2, flow3) { Unit }
t
No combine always complains about type mismatch when I mix up too many types
j
Did you try to specify
Any
explicitly?
As in
combine<Any, Unit>(...)
o
Or declare the lambda argument to help select the correct overload.
combine(flow1, flow2, flow3) { _ -> Unit }
t
Ok so yes
Copy code
{ _ -> }
does work, IDE says I should remove it but then it complains again about types ....
In the meantime I found flowOf().flattenConcat() but not sure to understand the difference between
j
You mean creating a flow of your flows and using
flattenConcat
? This won't have the effect you want, it will first give you all elements from the first flow until completion and then the elements of the next flow, etc. So you won't have interleaved events from different flows
t
Ok thanks will keep with combine, thanks for the type fix.
👍 1
o
I think you are looking for merge(..)