arrow-fx-coroutines / arrow.fx.coroutines.stream / terminateOn

terminateOn

fun <O> Stream<O>.terminateOn(terminator: (O) -> Boolean): Stream<O>

Halts the input stream when the condition is true.

import arrow.fx.coroutines.stream.*

//sampleStart
suspend fun main(): Unit =
  Stream(1, 2, 3, 4)
    .terminateOn { it == 3 }
    .toList()
    .let(::println) //[1, 2]
//sampleEnd

Do you like Arrow?

Arrow Org
<