UNPKG

@lou.codes/iterables

Version:
23 lines (22 loc) 585 B
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); } });