Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mapsome

coderaiser3.6kMIT1.0.0

find maped element of an array that will satisfy condition of some

map, some, array, functional, list

readme

Mapsome License NPM version Dependency Status Build Status

Find maped element of an array that will satisfy condition of some.

Map + Some + early return of an element;

Install

npm i mapsome --save

How come?

Lets look at regular map-filter example:

const map = (a) => ++a;
const condition = (a) => a > 2;

[1, 2, 3, 4]
    .map(map)           /* loop full array */
    .filter(condition)  /* loop full array again */
    .pop();             /* get value */
// returns
3

With mapsome this would look this way:

const map = (a) => ++a;
const condition = (a) => a > 2;

mapsome(map, condition, [1, 2, 3, 4]);
// returns
3

mapsome works much faster because no need map full array, first satisfied condition will break the loop.

API

mapsome(map [, condition ], array)

  • mapping function
  • condition of stopping the loop
  • array

mapsome could be used with map function only:

const map = (a) => ++a;
mapsome(map, [0, 0, 3, 0]);
// returns
3

// same as
mapsome(map, a => a, [0, 0, 3, 0]);
// returns
3

Environments

Node.js

In old node.js environments that supports es5 only, mapsome could be used with:

var mapsome = require('mapsome/legacy');

Web Browser

mapsome could be installed via bower with:

bower install mapsome --save

When loaded in browser mapsome uses global variable with same name (when browserify or webpack did not used).

License

MIT