node package manager
Loosely couple your services. Use Orgs to version and reuse your code. Create a free org »


map-iterable analog for iterables.

Travis Build Status Coveralls NPM module NPM downloads

The map() method creates a new iterable with the results of calling a provided function on every element in given iterable.

The function is curried, so you can omit the data argument and you get a function that map over the provide function.


npm install --save map-iterable


    const map = require('map-iterable');
    const numbers = [1, 4, 9];
    const roots = Array.from(
        map(Math.sqrt, numbers)
// roots is now [1, 2, 3], numbers is still [1, 4, 9] 

using curry

    const map = require('map-iterable');
    const mapSqrt = map(Math.sqrt);
    const numbers = [1, 4, 9];
    const roots = Array.from(mapSqrt(numbers))
// roots is now [1, 2, 3], numbers is still [1, 4, 9] 


map(callback, data)


  • callback: Function | Object

If a function is provided, it shall be the callback that produces an element of the new Iterable, taking three arguments: - currentValue - The current element being processed in the iterable. - index - The index of the current element being processed in the iterable. - context - an object shared between all calls to the function.

If an object is provided, it is interpreted as on option object with following properties:

* callback: Function - see above
* init: Function - optional init function that must return the initial value for `context`. If it's not provided, the iterable itself will be used as `context` initial value.
  • data: Iterable

The source iterable to iterate over.

Return value

A new array with each element being the result of the callback function.


The MIT License (MIT)

Copyright (c) 2016 Andrea Parodi