effect-io-ai

Package: effect
Module: Stream

Stream.runFold

Runs the stream and folds elements using a pure reducer.

Example (Folding stream values)

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

const program = Effect.gen(function*() {
  const total = yield* Stream.runFold(
    Stream.make(1, 2, 3),
    () => 0,
    (acc, n) => acc + n
  )
  yield* Console.log(total)
})

Effect.runPromise(program)
// 6

Signature

declare const runFold: { <Z, A>(initial: LazyArg<Z>, f: (acc: Z, a: A) => Z): <E, R>(self: Stream<A, E, R>) => Effect.Effect<Z, E, R>; <A, E, R, Z>(self: Stream<A, E, R>, initial: LazyArg<Z>, f: (acc: Z, a: A) => Z): Effect.Effect<Z, E, R>; }

Source

Since v2.0.0