Hyperlinkv0.8.0-beta.28

Stream

Stream.zipWithIndexconsteffect/Stream.ts:3856
<A, E, R>(self: Stream<A, E, R>): Stream<[A, number], E, R>

Zips this stream together with the index of elements.

Example (Zipping elements with indices)

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

const program = Effect.gen(function*() {
  const indexed = yield* Stream.make("a", "b", "c", "d").pipe(
    Stream.zipWithIndex,
    Stream.runCollect
  )
  yield* Console.log(indexed)
})

Effect.runPromise(program)
// Output: [["a", 0], ["b", 1], ["c", 2], ["d", 3]]
zipping
Source effect/Stream.ts:38561 lines
export const zipWithIndex = <A, E, R>(self: Stream<A, E, R>): Stream<[A, number], E, R> => map(self, (a, i) => [a, i])