diff --git a/kyo-prelude/shared/src/main/scala/kyo/Batch.scala b/kyo-prelude/shared/src/main/scala/kyo/Batch.scala index caae2dfa8..87cbd0c31 100644 --- a/kyo-prelude/shared/src/main/scala/kyo/Batch.scala +++ b/kyo-prelude/shared/src/main/scala/kyo/Batch.scala @@ -149,19 +149,20 @@ object Batch: case Expanded(_, source, _) => source case _ => () // Used as a placeholder for items that aren't source calls } - Kyo.foreach(pending.toSeq) { - case (_: Unit, items) => - // No need for flushing - Chunk.from(items) - case (source: SourceAny, items: Seq[Expanded] @unchecked) => - // Only request distinct items from the source - source(items.map(_.value).distinct).map { results => - // Reassemble the results by iterating on the original collection - Kyo.foreach(items) { e => - // Note how each value can have its own effects - capture(results(e.value).map(e.cont)) + Kyo.foreach(pending.toSeq) { tuple => + (tuple: @unchecked) match + case (_: Unit, items) => + // No need for flushing + Chunk.from(items) + case (source: SourceAny, items: Seq[Expanded] @unchecked) => + // Only request distinct items from the source + source(items.map(_.value).distinct).map { results => + // Reassemble the results by iterating on the original collection + Kyo.foreach(items) { e => + // Note how each value can have its own effects + capture(results(e.value).map(e.cont)) + } } - } } end flush