method StreamClass.prototype.tap
Private
StreamClass.prototype.tap(fn: (
value: T,
index: number
) => void | PromiseLike<void>
): StreamClass<T, E>

Runs fn per value as a lazy side effect and passes everything through unchanged — Elixir's lazy Stream.each/2, under the idiomatic JS name. Nothing runs until a consumer pulls; pair with StreamClass#run for side effects alone.

const seen: number[] = [];
await Stream.from([1, 2]).tap((n) => void seen.push(n)).collect(); // [1, 2]
seen; // [1, 2]

Parameters

fn: (
value: T,
index: number
) => void | PromiseLike<void>

Return Type

Usage

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