Skip to content

WebForgeOSS/chain-fns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Chain a list of handlers with each other

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •