take
take<
T>(iterable,count):IterableIterator<T>
Defined in: packages/core/src/iterable/take.ts:17
Yields at most the first count elements, then stops.
What Array.prototype.slice(0, count) does for an array, without
materialising, and without needing to know the length up front. The source is
closed as soon as the quota is met, so taking from an infinite iterable
terminates.
Time complexity: O(count).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The input iterable.
number
How many elements to yield. Must be a non-negative integer; zero yields nothing and consumes nothing.
Returns
Section titled “Returns”IterableIterator<T>
An iterator over the leading elements.
Throws
Section titled “Throws”If count is not a non-negative integer.