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

effect

fun <O> effect(fo: suspend () -> O): Stream<O>

Creates a single element stream that gets its value by evaluating the supplied effect. If the effect fails, the returned stream fails.

import arrow.core.Either
import arrow.fx.coroutines.*
import arrow.fx.coroutines.stream.*

//sampleEnd
suspend fun main(): Unit {
  Stream.effect { 10 }
    .toList()
    .let(::println) // [10]

  Either.catch {
    Stream.effect { throw RuntimeException() }
      .toList()
  }.let(::println) // Left(java.lang.RuntimeException)
}
//sampleStart

Do you like Arrow?

Arrow Org
<