Socket
Book a DemoInstallSign in
Socket

mekanika-utils-each

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mekanika-utils-each

Functional style immutable collection iterator `each( fn, collection )`

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

mekanika-utils-each

Functional style immutable collection iterator.

Installation

Install with npm:

$ npm install mekanika-utils-each

Or install with component(1):

$ component install mekanika/utils-each

API

Applies a function to a collection (either an Object or Array) and returns the unmodified collection.

each( iteratorFn, collection );

Params

  • iteratorFn {Function} Called for each element in the collection. Receives params:

    • value {Mixed} The value of the current element in the collection
    • index {Number|String} Current index, Number for array, String for object
    • collection {Object|Array} A reference to the collection being iterated
  • collection {Object|Array} The collection to be iterated

Returns

  • collection {Object|Array} A reference to the original collection

Usage

Setup

Using node:

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

To use in a browser:

$ make component

and then include as:

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

Examples

Iterating arrays:

each( function(v) { console.log( v*3 ) }, [1,2,3] );
// 3
// 6
// 9
// -> [1,2,3]

Iterating object properties:

each( function(v) { console.log( v*2 ) }, {a:2,b:3,c:4} );
// 4
// 6
// 8
// -> {a:2,b:3,c:4}

Functional style: partial application and subsequent calling:

var logSqrt = each( function(v) { console.log( Math.sqrt(v) ) } );
logSqrt( [1,2,3] );
// 1
// 1.41421...
// 1.73205...
// -> [1,2,3]

License

MIT

Keywords

for

FAQs

Package last updated on 02 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