How to combine for example flows? ```private fun ...
# getting-started
j
How to combine for example flows?
Copy code
private fun <T1, T2, T3, T4, T5, T6, T7, R> combine(
    flow: Flow<T1>,
    flow2: Flow<T2>,
    flow3: Flow<T3>,
    flow4: Flow<T4>,
    flow5: Flow<T5>,
    flow6: Flow<T6>,
    flow7: Flow<T7>,
    transform: suspend (T1, T2, T3, T4, T5, T6, T7) -> R
): Flow<R> = combine(
    combine(flow, flow2, flow3, ::Triple),
    combine(flow4, flow5, flow6, ::Triple),
    combine(flow7)
) { t1, t2, t3 ->
    transform(
        t1.first,
        t1.second,
        t1.third,
        t2.first,
        t2.second,
        t2.third,
        t3.first,
    )
}
What i need to put combine(flow7) really struggle 😞
e
just use the varargs/list version,
Copy code
inline fun <T1, T2, T3, T4, T5, T6, T7, R> combine(
    flow1: Flow<T1>,
    flow2: Flow<T2>,
    flow3: Flow<T3>,
    flow4: Flow<T4>,
    flow5: Flow<T5>,
    flow6: Flow<T6>,
    flow7: Flow<T7>,
    crossinline transform: suspend (T1, T2, T3, T4, T5, T6, T7) -> R
): Flow<R> = combine(listOf(
    flow1,
    flow2,
    flow3,
    flow4,
    flow5,
    flow6,
    flow7
)) { (value1, value2, value3, value4, value5, value6, value7) ->
    transform
(value1, value2, value3, value4, value5, value6, value7)
}
it involves an unchecked cast, but consumers don't have to worry about that
oh I forgot to actually include the unchecked casts,
Copy code
transform(value1 as T1, value2 as T2, value3 as T3, value4 as T4, value5 as T5, value6 as T6, value7 as T7)
but hopefully that was clear anyway