mys

mystery

flawless arrays processing

Showing:

Popularity

Downloads/wk

8

GitHub Stars

2

Maintenance

Last Commit

2yrs ago

Contributors

1

Package

Dependencies

3

Size (min+gzip)

1.3KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Mystery License NPM version Dependency Status Build Status Coverage Status

Flawless arrays processing.

Install

npm i mystery --save

Why?

When you use forEach, map, filter you have 2 conses to think about:

  • it is not as simple as could be add and remove elements in the middle of array
  • you should pass through the array again and again

This is where mystery shows up it's proses. It processes elements of an array one-by-one. So you have only one array walk. Similar to the way of node.js stream works, mystery is something like pipe it joins all transforms which are event emitters from the inside.

How to use?

const mystery = require('mystery');
const {map, filter, take, append, insert} = mystery;
const mapper = mystery([
    map((a) => a * a)),
    filter((a) => a > 10)),
    take(2),
    append(['yes', 'you', 'can']),
    insert(4, 'definitely')
]);

mapper([1, 2, 3, 4, 5], (array) => {
    console.log(array);
    // returns
    [16, 25, 'yes', 'you', 'definitely', 'can']
});

Transforms

You can use any of built-in transforms or write your own. Consder simple head and tail transforms which returns first and rest elements.

This is how head transform could look like:

const mystery = require('mystery');

const head = () => {
    return (value, index, emit) => {
        if (!index)
            emit(value);
    }
};

const first = mystery([
    head()
]);

first([1, 2, 3, 4, 5], (array) => {
    console.log(array);
    // result
    [1]
});

And here is tail:

const mystery = require('mystery');

const tail = () => {
    return (value, index, emit) => {
        if (index)
            emit(value);
    }
};

const rest = mystery([
    tail()
]);

first([1, 2, 3, 4, 5], (array) => {
    console.log(array);
    // returns
    [2, 3, 4, 5]
});

You can find more examples at lib/transforms.

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100