method StreamClass.prototype.withIndex
Private
StreamClass.prototype.withIndex(offset?: number): StreamClass<readonly [T, number], E>

Pairs each value with its index: [value, index]. Failures pass bare and consume no index — pairs stay contiguous.

await Stream.from(['a', 'b']).withIndex(1).collect(); // [['a', 1], ['b', 2]]

Parameters

optional
offset: number = 0

Return Type

StreamClass<readonly [T, number], E>

Usage

import { StreamClass } from "lib/stream/stream.ts";