p-j-s
A library to parallelize map
, filter
and reduce
operations on typed arrays through the use of Web Workers.
Installing
npm i p-j-s
Usage
It's as simple as:
var pjs = require('p-j-s');
pjs.init();
pjs(new Uint32Array([1,2,3,4]))
.filter(function(e){
return e % 2 === 0;
}).map(function(e){
return e * 2;
}).seq(function(err, result){
pjs.terminate();
});
Operations
map
The map
operation invokes the mapper
function on each element of the wrapped TypedArray
. It produces a new array of the same type where each element is the result of the mapper
function.
filter
The filter
operation invokes the predicate
function on each element of the wrapped TypedArray
. It produces a new array of the same type which only includes the original elements for which the predicate
function returns true
(or a truthy value).
reduce
The reduce
operation invokes the reducer
function on each element of the wrapped TypedArray
passing the value of the previous invocation as current
.
The reduction is first performed in the Web Workers using identity
as the intial value for current
. The results from the Web Workers are collected and a new reduction is performed on them using seed
and identityReducer
function.
Documentation
You can find out more by checking out the complete API and the How Tos in our wiki.
Acknowledgements