Skip to content
/ map Public

Replaces each item in the array with the result of an asynchronous or synchronous iterator

License

Notifications You must be signed in to change notification settings

chainyjs/map

Repository files navigation

Map action for ChainyJS

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Slack community badge Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

Chainy action that replaces each item in the array with the result of an asynchronous or synchronous iterator

The iterator can operate synchronously:

function (value) {
	return replacementValue
}

Or asynchronously:

function (value, complete) {
	complete(err, replacementValue)
}

Iterators are executed in parallel.

The replacement value (or lack thereof) is used to replace the value of the item in the array the iterator was executing for. Be sure to always explicitly specify a replacement value (even if it is the same as the value), as otherwise the item in the array will be replaced with undefined and you'll be confused.

Example:

require('chainy').create().require('set map log')
	.set([1, 2, 3])

	// Synchronous iterator
	.map(function (i) {
		return i * 5;
	}).log()  // [5, 10, 15]

	// Asynchronous iterator
	.map(function (i, next) {
		return next(null, i * 10);
	}).log()  // [10, 20, 30]

Install

NPM

  • Install: npm install --save chainy-plugin-map
  • Module: require('chainy-plugin-map')

Browserify

  • Install: npm install --save chainy-plugin-map
  • Module: require('chainy-plugin-map')
  • CDN URL: //wzrd.in/bundle/[email protected]

Ender

  • Install: ender add chainy-plugin-map
  • Module: require('chainy-plugin-map')

This package is published with the following editions:

  • chainy-plugin-map aliases chainy-plugin-map/source/index.js
  • chainy-plugin-map/source/index.js is Source + ES5 + Require

History

Discover the release history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under:

About

Replaces each item in the array with the result of an asynchronous or synchronous iterator

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published