https://github.com/stoeffel/compose-function
Function composition
https://github.com/stoeffel/compose-function
Last synced: 8 months ago
JSON representation
Function composition
- Host: GitHub
- URL: https://github.com/stoeffel/compose-function
- Owner: stoeffel
- License: mit
- Created: 2015-01-04T09:12:28.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-11-07T17:21:19.000Z (about 6 years ago)
- Last Synced: 2025-03-31T12:07:18.689Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 56
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-fp-js - compose-function
- fucking-awesome-fp-js - compose-function
- awesome-micro-npm-packages - compose-function - Compose a new function from smaller functions `f(g(x))`. (Modules / Function)
- awesome-micro-npm-packages-zh - compose-function
- awesome-micro-npm-packages - compose-function - Compose a new function from smaller functions `f(g(x))`. (Modules / Function)
- fucking-awesome-micro-npm-packages - compose-function - Compose a new function from smaller functions `f(g(x))`. (Modules / Function)
README
[](https://travis-ci.org/stoeffel/compose-function)
[](https://www.npmjs.com/package/compose-function)
[](https://david-dm.org/stoeffel/compose-function)
[](https://coveralls.io/github/stoeffel/compose-function)
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 --save`
Usage
-----
## Basic usage
```js
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
```js
import compose from 'compose-function';
import { curry, _ } from 'curry-this';
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](https://github.com/jussi-kalliokoski/trine/blob/5b735cbfb6b28ae94bac0446d9ecd5ce51fb149b/README.md#why) by [@jussi-kalliokoski](https://github.com/jussi-kalliokoski) or have a look at the [function bind syntax proposal](https://github.com/zenparsing/es-function-bind).
Or checkout the [curry-this docs][ct].
Related
----
* [curry-this][ct]
License
----
MIT © [Christoph Hermann](http://stoeffel.github.io)
[r]: http://ramdajs.com
[ct]: https://github.com/stoeffel/curry-this