Hyperlinkv0.8.0-beta.28

Stream

Stream.pipeThroughconsteffect/Stream.ts:9138
<A2, A, L, E2, R2>(sink: Sink.Sink<A2, A, L, E2, R2>): <E, R>(
  self: Stream<A, E, R>
) => Stream<L, E2 | E, R2 | R>
<A, E, R, A2, L, E2, R2>(
  self: Stream<A, E, R>,
  sink: Sink.Sink<A2, A, L, E2, R2>
): Stream<L, E | E2, R | R2>

Pipes the stream through Sink.toChannel, emitting only the sink leftovers.

Details

If the sink completes mid-chunk, the remaining elements become the output stream.

Example (Piping through a sink)

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

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

  yield* Console.log(leftovers)
})

Effect.runPromise(program)
//=> [ 3, 4 ]
Pipe
Source effect/Stream.ts:913812 lines
export const pipeThrough: {
  <A2, A, L, E2, R2>(sink: Sink.Sink<A2, A, L, E2, R2>): <E, R>(self: Stream<A, E, R>) => Stream<L, E2 | E, R2 | R>
  <A, E, R, A2, L, E2, R2>(self: Stream<A, E, R>, sink: Sink.Sink<A2, A, L, E2, R2>): Stream<L, E | E2, R | R2>
} = dual(
  2,
  <A, E, R, A2, L, E2, R2>(self: Stream<A, E, R>, sink: Sink.Sink<A2, A, L, E2, R2>): Stream<L, E | E2, R | R2> =>
    self.channel.pipe(
      Channel.pipeToOrFail(Sink.toChannel(sink)),
      Channel.concatWith(([_, leftover]) => leftover ? Channel.succeed(leftover) : Channel.empty),
      fromChannel
    )
)