effect-io-ai

Package: effect
Module: Stream

Stream.toAsyncIterableEffect

Creates an effect that yields an AsyncIterable using the current services.

When to use

Use when the AsyncIterable should be created inside Effect with the current context supplying the stream’s services.

Example (Creating an AsyncIterable effect)

import { Effect, Stream } from "effect"

const stream = Stream.make(1, 2, 3)

const program = Effect.gen(function*() {
  const iterable = yield* Stream.toAsyncIterableEffect(stream)
  const values = yield* Effect.promise(async () => {
    const collected: Array<number> = []
    for await (const value of iterable) {
      collected.push(value)
    }
    return collected
  })
  yield* Effect.sync(() => console.log(values))
})

Effect.runPromise(program)
// [ 1, 2, 3 ]

Signature

declare const toAsyncIterableEffect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<AsyncIterable<A>, never, R>

Source

Since v3.15.0