arrow-fx-coroutines / arrow.fx.coroutines.stream / Stream / fold
fun <B> fold(initial: B, f: (B, O) -> B):
Stream
<B>
Folds all inputs using an initial value z
and supplied binary operator,
and emits a single element stream.
import arrow.fx.coroutines.stream.*
//sampleStart
suspend fun main(): Unit =
Stream(1, 2, 3, 4, 5)
.fold(0) { acc, b -> acc + b }
.toList()
.let(::println) //[15]
//sampleEnd
Do you like Arrow?
✖