• Given an IteratorArg and a mapping function, returns a new IterableIterator that yields values from the initial iterator but passed through the mapping function.

    Type Parameters

    • TValue

      The value returned from the iterator

    • TMapperReturn

      The return type of your reducer function

    • TReturn = undefined | TValue

      If your iterator has a return type it must be the same as TIteratorValue, otherwise undefined

    • TNext = any

      The type your iterator is expecting as what's passed to its next function. For generators this is the type returned after a yield.

    Parameters

    • iterator: IteratorArg<TValue, TReturn, TNext>

      The iterator you wish to map elements from

    • mapper: ((arg) => TMapperReturn)

      A function to use to map the elements iterator produces

        • (arg): TMapperReturn
        • Parameters

          • arg: TValue

          Returns TMapperReturn

    Returns AugmentedIterator<TMapperReturn, TReturn, TNext>

    Example

    const set = new Set([1, 2, 3, 4, 5]);

    const mapped = mapIterator(set, (item) => item * 2);

    console.log(Array.from(mapped)); // logs out [2, 4, 6, 8, 10]

Generated using TypeDoc