chain-fns
v1.0.0
Published
Chain a list of handlers with each other
Downloads
2
Readme
chain-fns
Create a chain of responsability by chaining a list of handlers
Install
$ npm install s-chain-fns
Usage
const chainFns = require("s-chain-fns");
const divideByTwo = next => num => next(num / 2);
const addOne = next => num => next(num + 1);
const stopChainIfOdd = next => num => (num % 2 === 0 ? next(num) : num);
const thousandTimes = next => num => next(num * 1000);
const operations = chainFns([double, addOne, stopChainIfOdd, thousandTimes]);
operations(10); //=> 6000
operations(12); //=> 7
API
chainFns(fns) ⇒ Function
Chain a list of handlers with each other
Returns: Function - First handler chains with the others
| Param | Type | Description | | ----- | ----------------------- | ------------------------- | | fns | Function[] | List of handlers to chain |
fns
Type: Function[]
Each functions should be curried with the first parameter being the next function they are chain with.
const handler1 = next => (param1, param2, param3, ...) => {
// content of the function
}
License
MIT © saxjst