Hyperlinkv0.8.0-beta.28

Stream

Stream.syncconsteffect/Stream.ts:876
<A>(evaluate: LazyArg<A>): Stream<A>

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 ]
constructors
Source effect/Stream.ts:8761 lines
export const sync = <A>(evaluate: LazyArg<A>): Stream<A> => fromChannel(Channel.sync(() => Arr.of(evaluate())))