Arrays.map()

Iterate over each item of an array to build a new transformed array.

Unlike the native Javascript `.map()` function, the Map machine is not guaranteed to return an array with the same length as the input. This is due to the availability of the `skip` exit in the iteratee, which allows for skipping an array item completely.

Usage

Hover over inputs/exits for more info.

var Arrays = require('machinepack-arrays');


// Iterate over each item of an array to build a new transformed array.

Arrays.map({

array: [ '*' ],

iteratee: '->',

resultExemplar: [ '*' ],

series: false,

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function () {

 

},

});

Inputs

array required

The array to loop over

[ '*' ]
iteratee required

The transformation to run for each item in the array.

'->'
resultExemplar

An example of what the final result array will look like.

[ '*' ]
series

Whether to run iteratee on one item at a time (in series)

false

Exits

error

An unexpected error occurred.

success

OK.

(varies based on provided inputs)