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

effectMapAccumulate

fun <S, O2> effectMapAccumulate(s: S, f: suspend (S, O) -> Pair<S, O2>): Stream<Pair<S, O2>>

Like mapAccumulate, but accepts a function returning an suspend fun.

import arrow.fx.coroutines.*
import arrow.fx.coroutines.stream.*

//sampleStart
suspend fun main(): Unit =
  Stream(1,2,3,4)
    .effectMapAccumulate(0) { acc, i ->
      sleep((i * 10).milliseconds)
      Pair(i, acc + i)
    }
    .toList()
    .let(::println) // [(1,1), (2,3), (3,5), (4,7)]
//sampleEnd

Do you like Arrow?

Arrow Org
<