chain-fns

1.0.0 • Public • Published

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

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

Readme

Keywords

Package Sidebar

Install

npm i chain-fns

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.97 kB

Total Files

8

Last publish

Collaborators

  • saxjst