API · Select

take()

Emit at most the first `n` successful values, then stop this branch.

Signature

take(n: number): Exstream<T, C>

Example

const preview = await exstream(largeSource).take(10).toPromise()

Parameters

n

Type numberRequired

Exclusive upper index, passed to slice(0, n). It must parse to a number greater than zero; fractions are accepted and therefore round up in effect.

Behavior

take(n) is exactly slice(0, n). It preserves order and context, adds no independent buffer, and destroys its branch once the limit is reached. The implementation can consume one additional successful source value while detecting the boundary; that value is not emitted. Shared forks continue independently.

Record errors pass through and do not count toward n. take(0), negative counts, and NaN are rejected because the resulting slice has no valid start < end range. Use an empty source when zero output is required.

Forms

stream.take(10)
exstream.pipeline().take(10)
exstream.take(10, stream)
stream.through(exstream.take(10))

slice(), head(), stopWhen()