StreamClass.prototype.through<U>(fn: (elements: AsyncIterable<T | E>) => Source<U>): StreamClass<Exclude<U, AnyFailure>, Extract<U, AnyFailure>>
The general engine — Elixir's Stream.transform, JS-shaped: hand the raw element flow
to your own async generator and yield whatever you want. The one transform where
failures do not auto-pass: your generator sees them and owns the ruling. Every
missing combinator is three lines away through this.
const pairs = Stream.from([1, 2, 3, 4]).through(async function* (elements) { let previous: number | undefined; for await (const n of elements) { if (previous !== undefined) yield [previous, n] as const; previous = n; } }); await pairs.collect(); // [[1, 2], [2, 3], [3, 4]]
StreamClass<Exclude<U, AnyFailure>, Extract<U, AnyFailure>>