since combineLatest with multiple sources is now d...
# coroutines
m
since combineLatest with multiple sources is now deprecated, how to get the latest result from multiple flows ?
g
combineLatest
is only in the API to help migrate from RxJava and others. Just like a lot of other operators. Take a look at https://github.com/Kotlin/kotlinx.coroutines/blob/a70022d6e7d9aa5d8fe27a2c46e987a2e8b85c21/kotlinx-coroutines-core/common/src/flow/Migration.kt In this case the doc says to replace
combineLatest
with
combine
m
ok so let's say i need to combine 5 sources, i should just add the behavior with extension functions right ?
g
Copy code
public inline fun <T1, T2, T3, T4, T5, R> Flow<T1>.combineLatest(
    other: Flow<T2>,
    other2: Flow<T3>,
    other3: Flow<T4>,
    other4: Flow<T5>,
    crossinline transform: suspend (T1, T2, T3, T4, T5) -> R
): Flow<R> = combine(this, other, other2, other3, other4, transform)
I think 5 is the max you can combine with the built-in operator?
m
ok, that's what i thought, thanks
g
you don't need to add the behavior yourself though
m
yes, just the function with desired nr of flow arguments, and the mapper function body
👍 1