JSPM

map-iterable

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3880
  • Score
    100M100P100Q127593F
  • License MIT

Array.prototype.map analog for iterables.

Package Exports

  • map-iterable

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (map-iterable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

map-iterable

Array.prototype.map 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.

Installation

npm install --save map-iterable

Examples

    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];
    cons
    const roots = Array.from(mapSqrt(numbers))
// roots is now [1, 2, 3], numbers is still [1, 4, 9]

Syntax

map(callback, data)

Parameters

  • 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.

License

The MIT License (MIT)

Copyright (c) 2016 Andrea Parodi