mekanika-utils-map
Functional style map iterator map( fn, collection [, this] )
Overview
A standard map iterator for Objects and Arrays:
- Steps through each element in
collection
- Applies the transform function
fn( value )
- Returns the mutated collection
Main difference is that it flips traditional map
parameters around to
support currying, for partial application of mutator functions for mapping:
var square = ;// -> {Function} (partially applied map);// -> [1,4,9]
Installation
Install with npm:
$ npm install mekanika-utils-map
Install with component(1):
$ component install mekanika/utils-map
API
;
Requires
Params
-
mutatorFn
{Function} Called for each element of collection. Passed:value
{Mixed} The value of the current iterator elementindex
_{Number|String} The element index (Number for array, String for Object)collection
{Object|Array}
-
collection
{Object|Array} The collection of elements to iterate -
thisBinding
(*) Optionalthis
binding for the mutatorFn callback
Returns
modifiedCollection
{Object|Array} The mutated collection of elements
Usage
For node:
var map = ;
For use in a browser, first build the file:
$ make component
Then include
Examples
Arrays and objects:
;// -> [1,4,9] ;// -> [6,7,8]
Functional programming partial application:
var square = ;// -> {Function} (partially applied map);// -> [1,4,9]
License
MIT