Hyperlinkv0.8.0-beta.28

Stream

Stream.zipconsteffect/Stream.ts:3685
<A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(
  self: Stream<A, E, R>
) => Stream<[A, A2], E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
  self: Stream<A, E, R>,
  that: Stream<A2, E2, R2>
): Stream<[A, A2], E | E2, R | R2>

Zips this stream with another point-wise and emits tuples of elements from both streams. The new stream ends when either stream ends.

Example (Zipping streams)

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

const stream1 = Stream.make(1, 2, 3)
const stream2 = Stream.make("a", "b", "c")

const zipped = Stream.zip(stream1, stream2)

const program = Effect.gen(function*() {
  const result = yield* Stream.runCollect(zipped)
  yield* Console.log(result)
})

Effect.runPromise(program)
// Output: [[1, "a"], [2, "b"], [3, "c"]]
zipping
Source effect/Stream.ts:368510 lines
export const zip: {
  <A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<[A, A2], E2 | E, R2 | R>
  <A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<[A, A2], E | E2, R | R2>
} = dual(
  2,
  <A, E, R, A2, E2, R2>(
    self: Stream<A, E, R>,
    that: Stream<A2, E2, R2>
  ): Stream<[A, A2], E | E2, R | R2> => zipWith(self, that, (a, a2) => [a, a2])
)