method StreamClass.prototype.map
Private
StreamClass.prototype.map<U>(fn: (
value: T,
index: number
) => U | PromiseLike<U>
): StreamClass<Exclude<U, AnyFailure>, E | Extract<U, AnyFailure>>

Transforms each value; failure elements flow past untouched (the railway, per element). fn may itself return a Failure — that widens the stream's E, which is how a parse step turns raw input into Row | BadRow without a wrapper per element. A throw inside fn is a bug and rejects the consumer.

fn is awaited one element at a time. map((url) => fetch(url)) issues its requests strictly in sequence — six 60ms calls take 360ms, not 60ms. That is not an oversight to route around: a stream is one suspended generator, so it has exactly one resume point, and the same constraint is why TC39's async iterator helpers are still unshipped over precisely this question. For concurrent per-element work use StreamClass.asyncStream, whose maxConcurrency bounds the window and whose ordered decides whether results keep source order or arrive as they finish.

const tagged = await Stream.from([1, 2]).map((n, i) => `${i}:${n}`).collect();
tagged; // ['0:1', '1:2']

Type Parameters

Parameters

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

Return Type

StreamClass<Exclude<U, AnyFailure>, E | Extract<U, AnyFailure>>

Usage

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