Jérémy CROS
06/23/2023, 12:50 PMcombine
operator but it doesn’t quite fit here
Any idea how we could do that? Thanks! 🙏Jérémy CROS
06/23/2023, 12:59 PMcombine
with all 3 flows then debounce
at 50ms would work?Lukáš Kúšik
06/26/2023, 8:35 AMJérémy CROS
06/26/2023, 9:37 AMNote that the resulting flow does not emit anything as long as the original flow emits items faster than every timeoutMillis milliseconds.
trying to play with flowmarbles and tbh, i’m kinda confused by all this operators 😅
there’s also sample
available or your suggestion which I will try 🤔gabfssilva
07/03/2023, 4:38 PMcombine
simply appends the two flows, but zip emits the items accordingly to their index, until both values from both indexes are emitted, the flow is backpressured:
data class Num(
val english: String,
val spanish: String,
val portuguese: String,
)
val englishFlow = flowOf("one", "two", "three", "four").onEach { delay(10) }
val spanishFlow = flowOf("un", "dos", "tres", "cuatro").onEach { delay(10) }
val portugueseFlow = flowOf("um", "dois", "três", "quatro").onEach { delay(70) }
val threeLanguagesFlow: Flow<Num> =
englishFlow
.zip(spanishFlow) { english, spanish -> english to spanish } // Flow<Pair<String, String>>
.zip(portugueseFlow) { (english, spanish), portuguese -> Num(english, spanish, portuguese) }
Once you collect threeLanguagesFlow
, the result will be:
Num(english=one, spanish=un, portuguese=um)
Num(english=two, spanish=dos, portuguese=dois)
Num(english=three, spanish=tres, portuguese=três)
Num(english=four, spanish=cuatro, portuguese=quatro)
Not entirely sure if that’s what you’re looking for, but, I hope it helps, @Jérémy CROS. 🙂Jérémy CROS
07/04/2023, 8:15 AMcombine
all 3 flows, map the data, emit the value then sample
on the period (50ms in my case). That seemed to work pretty well in practice 🙂
But thanks for your detailed answer! I’m not super familiar with zip and it could prove useful for another use case 🙏gabfssilva
07/04/2023, 1:14 PM