arrow-fx-coroutines / arrow.fx.coroutines.stream / Stream / zipWithScan
fun <B> zipWithScan(z: B, f: (B, O) -> B):
Stream
<
Pair
<O, B>>
Zips the input with a running total according to S
, up to but not including the current element. Thus the initial
z
value is the first emitted to the output:
import arrow.fx.coroutines.stream.*
//sampleStart
suspend fun main(): Unit =
Stream("uno", "dos", "tres", "cuatro")
.zipWithScan(0) { acc, b -> acc + b.length }
.toList()
.let(::println) //[(uno,0), (dos,3), (tres,6), (cuatro,10)]
//sampleEnd
See Also
Do you like Arrow?
✖