Function: take()
take<
ElementType>(iterable:IterableResolvable<ElementType>,count:number):IterableIterator<ElementType>
Defined in: projects/utilities/packages/iterator-utilities/src/lib/take.ts:23
Creates an iterable with the first count elements.
Type Parameters
| Type Parameter |
|---|
ElementType |
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | IterableResolvable<ElementType> | The iterator to take values from. |
count | number | The maximum number of values to take from the iterator. |
Returns
IterableIterator<ElementType>
An iterator that yields at most count values from the provided iterator.
Example
import { take } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log([...take(iterable, 2)]);
// Output: [1, 2]