arrow-fx-coroutines / arrow.fx.coroutines.stream / callback

callback

fun <A> Stream.Companion.callback(f: suspend EmitterSyntax<A>.() -> Unit): Stream<A>

Creates a Stream from the given suspended block callback, allowing to emit, set cancel effects and end the emission.

import arrow.fx.coroutines.stream.*

//sampleStart
suspend fun main(): Unit =
  Stream.callback {
      emit(1)
      emit(2, 3, 4)
      end()
    }
    .toList()
    .let(::println) //[1, 2, 3, 4]
//sampleEnd

Note that if neither end() nor other limit operators such as take(N) are called, then the Stream will never end.

Do you like Arrow?

Arrow Org
<