Skip to content

thunklife/fn-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fn-compose

A simple function to compose an arbitrary number of functions from right to left, or left to right.

install

npm install --save fn-compose

usage

var compose = require('fn-compose'),
	mul2 = function mul2(a){ return a * 2 },
	sub1 = function sub1(a){ return a - 1 },
	mul2Sub1 = compose(sub1, mul2);

mul2Sub1(5); //=> 9

There is also a left to right mode, which is exported as ltr:

var compose = require('fn-compose').ltr, // Notice the .ltr
	mul2 = function mul2(a){ return a * 2 },
	sub1 = function sub1(a){ return a - 1 },
	mul2Sub1 = compose(sub1, mul2);

mul2Sub1(5); //=> 8

license

MIT

About

A simple function to compose an arbitrary number of functions from right to left.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published