From 1c9731da85755a835ebbd85d9e4ee5aa15cd1721 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Tue, 12 Sep 2023 14:28:44 +0200 Subject: [PATCH] Added javadoc to List>.zipAll --- .../org/radarbase/kotlin/coroutines/flow/Extensions.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/flow/Extensions.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/flow/Extensions.kt index 416cdfd0..66ee4b20 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/flow/Extensions.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/flow/Extensions.kt @@ -5,15 +5,21 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.zip +/** + * Convert a list of flows to one flow with a list of values. The list contains the latest value of + * each respective flow, in the same order as the original flows. + */ fun List>.zipAll(): Flow> = when (val numberOfFlows = size) { 0 -> flowOf(listOf()) 1 -> first().map { listOf(it) } 2 -> first().zip(last()) { a, b -> listOf(a, b) } - else -> subList(0, numberOfFlows - 1) - .zipAll() + else -> subList(0, numberOfFlows - 1).zipAll() .zip(last()) { rest, last -> rest + last } } +/** + * Alias of [List.zipAll]. + */ fun zipAll( vararg flows: Flow, ): Flow> = flows.toList().zipAll()