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

bufferAll

fun bufferAll(): Stream<O>

Behaves like the identity stream, but emits no output until the source is exhausted.

import arrow.fx.coroutines.stream.*

//sampleStart
suspend fun main(): Unit {
  val buf = mutableListOf<String>()

  Stream.range(0..10)
    .effectTap { i -> buf.add(">$i") }
    .bufferAll()
    .effectTap { i -> buf.add("<$i") }
    .take(4)
    .toList()
    .let(::println) // [0, 1, 2, 3]

  println(buf.joinToString()) // [>0, >1, >2, >3, >4, >5, >6, >7, >8, >9, >10, <0, <1, <2, <3]
}
//sampleEnd

Do you like Arrow?

Arrow Org
<