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

mapAccumulate

fun <S, O2> mapAccumulate(init: S, f: (S, O) -> Pair<S, O2>): Stream<Pair<S, O2>>

Maps a running total according to S and the input with the function f.

import arrow.fx.coroutines.stream.*

//sampleStart
suspend fun main(): Unit =
  Stream("Hello", "World")
  .mapAccumulate(0) { l, s -> Pair(l + s.length, s.first()) }
  .toList()
  .let(::println) //[(5,H), (10,W)]
//sampleEnd

Do you like Arrow?

Arrow Org
<