Package Exports
- compose-function
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (compose-function) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Compose-Function
Installation |
Usage |
Related |
License
logo by Justin Mezzell
Compose a new function from smaller functions `f(g(x))`
Installation
npm install compose-function
Usage
Basic usage
import compose from 'compose-function';
const composition = compose(sqr, add2); // sqr(add2(x))
composition(2) // => 16
compose(sqr, inc)(2); // => 9
compose(inc, sqr)(2); // => 5
with curry
import compose from 'compose-function';
const { curry, _ } = require('curry-this')({Symbol:() => 'CURRY'});
const add = (x, y) => x + y;
// add(6, sqr(add(2, x)))
compose(
add::curry(6),
sqr,
add::curry(2),
);
// map(filter(list, even), sqr)
compose(
map::curry(_, sqr),
filter::curry(_, even),
)([1,2,3,4,5,6,7,8]) // => [4, 16, 36, 64]
::
huh?
If you’re wondering what the ::
thing means, you’d better read this excellent overview by @jussi-kalliokoski or have a look at the function bind syntax proposal.
Or checkout the curry-this docs.
Related
License
MIT © Christoph Hermann