Create a chain of responsability by chaining a list of handlers
$ npm install s-chain-fns
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); //=> 7Chain 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 |
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
}MIT © saxjst