arrow-fx-coroutines / arrow.fx.coroutines.stream / fold1
fun <O>
Pull
<O,
Unit
>.fold1(f: (O, O) -> O):
Pull
<
Nothing
, O?>
Folds all inputs using the supplied binary operator, and writes the final result to the output of
the supplied Pull
when the stream has no more values.
fun <O>
Stream
<O>.fold1(f: (O, O) -> O):
Stream
<O>
Folds all inputs using the supplied operator f, and emits a single-element stream, or the empty stream if the input is empty, or the never stream if the input is non-terminating.
import arrow.fx.coroutines.stream.*
//sampleStart
suspend fun main(): Unit =
Stream(1, 2, 3, 4, 5)
.fold1 { a, b -> a + b }
.toList()
.let(::println) // [15]
//sampleEnd
Do you like Arrow?
✖