@lou.codes/iterables
Version:
🔁 Iterable and AsyncIterable utils
17 lines (16 loc) • 484 B
JavaScript
import { EMPTY_ARRAY } from "@lou.codes/constants/empty.js";
import { reduce } from "./reduce.js";
/**
* Turns given iterable or asynchronous iterable into an array.
*
* @category Asynchronous Reducers
* @example
* ```typescript
* iterableToArray([1, 2, 3, 4]); // [1, 2, 3, 4]
* ```
* @param iterable Iterable to be turned into an array.
* @returns Array made of iterable items.
*/
export const iterableToArray = reduce(item => array => [...array, item])(
EMPTY_ARRAY,
);