effect-io-ai

Package: effect
Module: Stream

Stream.transduce

Applies a sink transducer to the stream and emits each sink result.

Example (Transducing with a sink)

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

const program = Effect.gen(function* () {
  const result = yield* Stream.make(1, 2, 3, 4).pipe(
    Stream.transduce(Sink.take(2)),
    Stream.runCollect
  )

  yield* Console.log(result)
  // Output: [ [ 1, 2 ], [ 3, 4 ] ]
})

Signature

declare const transduce: (<A2, A, E2, R2>(sink: Sink.Sink<A2, A, A, E2, R2>) => <E, R>(self: Stream<A, E, R>) => Stream<A2, E2 | E, R2 | R>) & (<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, sink: Sink.Sink<A2, A, A, E2, R2>) => Stream<A2, E2 | E, R2 | R>)

Source

Since v2.0.0