An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# map-iterable

[![Greenkeeper badge](https://badges.greenkeeper.io/parro-it/map-iterable.svg)](https://greenkeeper.io/)

> Array.prototype.map analog for iterables.

[![Travis Build Status](https://img.shields.io/travis/parro-it/map-iterable/master.svg)](http://travis-ci.org/parro-it/map-iterable)
[![NPM module](https://img.shields.io/npm/v/map-iterable.svg)](https://npmjs.org/package/map-iterable)
[![NPM downloads](https://img.shields.io/npm/dt/map-iterable.svg)](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