1.0.0 • Published 4 years ago

chain-fns v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

chain-fns

Build Status Coverage Status Maintainability Language grade: JavaScript tested with jest code style: prettier

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

ParamTypeDescription
fnsFunction[]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

1.0.0

4 years ago