froebel
Version:
TypeScript utility library
23 lines (22 loc) • 663 B
TypeScript
/**
* Takes `n` elements from the iterable `list` and returns them as an array.
*
* @example
* ```
* take(5, repeat(1, 2)) // -> [1, 2, 1, 2, 1]
* take(3, [1, 2, 3, 4]) // -> [1, 2, 3]
* take(3, [1, 2]) // -> [1, 2]
* ```
*/
export declare const takeList: <T>(n: number, list: Iterable<T>) => T[];
/**
* Takes `n` elements from the iterable `list` and returns them as a generator.
*
* @example
* ```
* [...take(5, repeat(1, 2))] // -> [1, 2, 1, 2, 1]
* [...take(3, [1, 2, 3, 4])] // -> [1, 2, 3]
* [...take(3, [1, 2])] // -> [1, 2]
* ```
*/
export declare function takeGenerator<T>(n: number, list: Iterable<T>): Generator<T>;