https://github.com/parro-it/map-iterable
Array.prototype.map analog for iterables.
https://github.com/parro-it/map-iterable
Last synced: 10 months ago
JSON representation
Array.prototype.map analog for iterables.
- Host: GitHub
- URL: https://github.com/parro-it/map-iterable
- Owner: parro-it
- License: mit
- Created: 2016-09-13T22:09:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-09T19:35:58.000Z (over 5 years ago)
- Last Synced: 2024-08-10T07:28:31.873Z (over 1 year ago)
- Language: JavaScript
- Size: 2.82 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# map-iterable
[](https://greenkeeper.io/)
> Array.prototype.map analog for iterables.
[](http://travis-ci.org/parro-it/map-iterable)
[](https://npmjs.org/package/map-iterable)
[](https://npmjs.org/package/map-iterable)
The map() method creates a new iterable with the results of calling a provided
function on every element in given iterable.
You can omit the data argument and you get a function that map over the provided
function.
# Installation
```bash
npm install --save map-iterable
```
# Examples
```js
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 partial apply**
```js
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]
```
# API
## map
Creates a new iterable with the results of calling `transform` function on every
element in `data` iterable. If you omit the data argument return a unary
function that accept the data argument and map over the provided function.
**Parameters**
* `transform`
**[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
a function that return an element of the new Iterable, receiving as arguments:
. currentValue - The current element being processed in the iterable. index -
The index of the current element being processed in the iterable.
* `data` **Iterable** The source iterable to iterate over.
Returns **Iterable** A new Iterable over results of the transform function.
# License
The MIT License (MIT)
© 2017 Andrea Parodi