diff --git a/conditional-kotlin/src/main/kotlin/com/linecorp/conditional/kotlin/ComposedCoroutineCondition.kt b/conditional-kotlin/src/main/kotlin/com/linecorp/conditional/kotlin/ComposedCoroutineCondition.kt index 3d130bc..540661d 100644 --- a/conditional-kotlin/src/main/kotlin/com/linecorp/conditional/kotlin/ComposedCoroutineCondition.kt +++ b/conditional-kotlin/src/main/kotlin/com/linecorp/conditional/kotlin/ComposedCoroutineCondition.kt @@ -55,16 +55,7 @@ class ComposedCoroutineCondition internal constructor( cancel(ds) throw e } - val it = ds.iterator() - var value = it.next().await() - while (it.hasNext()) { - val next = it.next().await() - value = when (operator) { - AND -> value && next - OR -> value || next - } - } - value + ds.await() } private suspend fun completed(d: Deferred) = d.isCompleted && shortCircuit(operator, d.await()) @@ -110,6 +101,18 @@ class ComposedCoroutineCondition internal constructor( return value() } + private suspend fun MutableList>.await() = with(iterator()) { + var value = next().await() + while (hasNext()) { + val next = next().await() + value = when (operator) { + AND -> value && next + OR -> value || next + } + } + value + } + override fun toString(): String { if (!alias.isNullOrBlank()) return alias assert(conditions.isNotEmpty())