effect-io-ai

Package: effect
Module: Stream

Stream.sync

Creates a stream that synchronously evaluates a function and emits the result as a single value.

Details

The function is evaluated each time the stream is run.

Example (Evaluating a value synchronously)

import { Console, Effect, Stream } from "effect"

const program = Effect.gen(function*() {
  const values = yield* Stream.sync(() => 2 + 1).pipe(Stream.runCollect)
  yield* Console.log(values)
})

Effect.runPromise(program)
// Output: [ 3 ]

Signature

declare const sync: <A>(evaluate: LazyArg<A>) => Stream<A>

Source

Since v2.0.0