1.0.5 • Published 5 years ago

pipe-array v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

License: MIT Build Status Coverage Status

pipe-array

Node.js module for optimizing performance in array chaining transformations, e.g.

array.filter(i => i % 2 === 0).map(i => i + 1);

Install

npm i --save pipe-array

Run tests

Jest based

npm run test

or

npm run test:watch

Example

import pipe from 'pipe-array';

const array = [1, 2, 4, 5, 6, 7, 8];

const outcome = pipe(array)
  .filter(i => i % 2 === 0)
  .map(i => i * 2)
  .build((p, i) => p + i, 0);
// [2, 4, 6, 8]
// [4, 8, 12, 16]
// 40

Recommendations

Use with large array >10e6 as it is still slower than: for-loop, for-of,forEach. But it is faster thanArray.prototype.map`.

Specification

pipe

Constructor

(array: any[]) => Pipe;

returns an object

{
  map(fn: Map): Pipe,
  filter(fn: Filter): Pipe;
  build: (fn?: Reduce, initialValue?: any) => any | any[];
}

witch can be chained with map and filter in any order many times.

map

(currentValue: any, currentIndex?: number, array?: any[]) => any;

Follows the Array.prototype.map specification.

filter

(element: any, index?: number, array?: any[], thisArg?: ThisType<any>) => boolean;

Follows the Array.prototype.filter specification.

build

(fn?: Reduce, initialValue?: any) => any | any[];boolean;

If no parameter provided just applies early defined maps and filters. If provided reduce function, outcome will be transformed

reduce

(accumulator: any | any[], currentValue: any, currentIndex?: number, array?: any[])

Follows the Array.prototype.reduce specification.

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.0.1

5 years ago