Socket
Book a DemoInstallSign in
Socket

mekanika-utils-map

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mekanika-utils-map

Functional style map iterator `map( fn, collection )`

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

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 = map( function(v) { return v*v; } );
// -> {Function} (partially applied map)
square( [1,2,3] );
// -> [1,4,9]

Installation

Install with npm:

$ npm install mekanika-utils-map

Install with component(1):

$ component install mekanika/utils-map

API

map( mutatorFn, collection [, thisBinding] );

Requires

Params

  • mutatorFn {Function} Called for each element of collection. Passed:

    • value {Mixed} The value of the current iterator element
    • index _{Number|String} The element index (Number for array, String for Object)
    • collection {Object|Array}
  • collection {Object|Array} The collection of elements to iterate

  • thisBinding (*) Optional this binding for the mutatorFn callback

Returns

  • modifiedCollection {Object|Array} The mutated collection of elements

Usage

For node:

var map = require('mekanika-utils-map');

For use in a browser, first build the file:

$ make component

Then include

<script src="build/mekanika-utils-map.js">

Examples

Arrays and objects:

map( function(v) { return v*v; }, [1,2,3] );
// -> [1,4,9]

map( function(v) { return v+5 }, {a:1, b:2, c:3} );
// -> [6,7,8]

Functional programming partial application:

var square = map( function(v) { return v*v; } );
// -> {Function} (partially applied map)
square( [1,2,3] );
// -> [1,4,9]

License

MIT

Keywords

map

FAQs

Package last updated on 05 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts