Hyperlinkv0.8.0-beta.28

Sink

Sink.forEachArrayconsteffect/Sink.ts:1810
<In, X, E, R>(
  f: (input: NonEmptyReadonlyArray<In>) => Effect.Effect<X, E, R>
): Sink<void, In, never, E, R>

A sink that executes the provided effectful function for every Chunk fed to it.

Example (Running effects for each chunk)

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

// Create a sink that processes chunks
const sink = Sink.forEachArray((chunk: ReadonlyArray<number>) =>
  Console.log(
    `Processing chunk of ${chunk.length} items: [${chunk.join(", ")}]`
  )
)

// Use it with a stream
const stream = Stream.make(1, 2, 3, 4, 5)
const program = Stream.run(stream, sink)

Effect.runPromise(program)
// Output: Processing chunk of 5 items: [1, 2, 3, 4, 5]
constructors
Source effect/Sink.ts:181010 lines
export const forEachArray = <In, X, E, R>(
  f: (input: NonEmptyReadonlyArray<In>) => Effect.Effect<X, E, R>
): Sink<void, In, never, E, R> =>
  fromTransform((upstream) =>
    upstream.pipe(
      Effect.flatMap(f),
      Effect.forever({ disableYield: true }),
      Pull.catchDone(() => endVoid)
    )
  )
Referenced by 2 symbols