arrow-fx-coroutines / arrow.fx.coroutines.stream / Stream / first

first

fun first(f: (O) -> Boolean): Stream<O>

Emits the first element of the stream for which the predicate is defined, or is empty.

import arrow.fx.coroutines.stream.*

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

Do you like Arrow?

Arrow Org
<