@lou.codes/iterables
Version:
🔁 Iterable and AsyncIterable utils
23 lines (22 loc) • 585 B
JavaScript
import { createIterableIterator } from "./createIterableIterator.js";
/**
* Map for iterables.
*
* @category Generators
* @example
* ```typescript
* const double = value => value * 2;
* const mapDouble = map(double);
*
* mapDouble([1, 2, 3]); // [2, 4, 6]
* ```
* @param mapper Mapper function.
* @returns Generator function with `mapper` function set in context.
*/
export const map = mapper => iterable =>
createIterableIterator(function* () {
// eslint-disable-next-line functional/no-loop-statements
for (const item of iterable) {
yield mapper(item);
}
});