method StreamClass.prototype.take
Private
StreamClass.prototype.take(count: number): StreamClass<T, E>

Ends the stream after count elements (values and failures both count — take bounds work, it does not editorialize). The source is never pulled past the cut, which is the whole point over an eager slice: unfold pagination stops fetching.

let pulled = 0;
const firstTwo = Stream.unfold(0, (n) => ((pulled += 1), [n, n + 1] as const)).take(2);
await firstTwo.collect(); // [0, 1] — and pulled is 2, not ∞

Parameters

count: number

Return Type

Usage

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