commonMain.ua.railian.data.result.flow.flow-extensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of data-result-combine-flows Show documentation
Show all versions of data-result-combine-flows Show documentation
DataResult is a discriminated union that encapsulates a successful outcome with a value of type [T] or a failure with an error of type [E].
package ua.railian.data.result.flow
import kotlinx.coroutines.flow.Flow
//region Kotlin combine extensions
/**
* Returns a [Flow] whose values are generated with [transform] function by combining
* the most recently emitted values by each flow.
*/
@Suppress("UNCHECKED_CAST")
public fun combine(
flow: Flow,
flow2: Flow,
flow3: Flow,
flow4: Flow,
flow5: Flow,
flow6: Flow,
transform: suspend (T1, T2, T3, T4, T5, T6) -> R
): Flow = kotlinx.coroutines.flow.combine(
flow, flow2, flow3, flow4, flow5, flow6,
) { args: Array<*> ->
transform(
args[0] as T1,
args[1] as T2,
args[2] as T3,
args[3] as T4,
args[4] as T5,
args[5] as T6,
)
}
//endregion