StreamClass.prototype.forEach(fn: (value: T,index: number) => void | PromiseLike<void>): Task<void, E>
Drains the stream, running fn per value — fail-fast like StreamClass#collect.
The Task resolves when the source ends; use it when the work is the side effect.
Elixir's Stream.each/2 is the lazy tap, which lives here as StreamClass#tap because
that is the name JS gave it. This is the terminal drain, and it takes JS's name for that:
every iterable in the language spells it forEach — Array, Map, Set, and
Iterator.prototype since ES2025 — as do Rust's StreamExt::for_each and TC39's pending
async iterator helpers. Array.prototype.each has never existed.
Sequential, for the same reason StreamClass#map is: the next element is not pulled
until fn has settled. That is what makes it safe to write to a database from here, and
what makes it the wrong place to fan out — StreamClass.asyncStream is.
const seen: number[] = []; await Stream.from([1, 2, 3]).forEach((n) => void seen.push(n)); seen; // [1, 2, 3]
fn: (value: T,index: number) => void | PromiseLike<void>