Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ndhoule/compose
Compose a list of functions into a single function.
https://github.com/ndhoule/compose
Last synced: 13 days ago
JSON representation
Compose a list of functions into a single function.
- Host: GitHub
- URL: https://github.com/ndhoule/compose
- Owner: ndhoule
- License: mit
- Created: 2015-02-25T09:36:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-02T20:02:23.000Z (over 8 years ago)
- Last Synced: 2024-10-13T00:11:42.863Z (about 1 month ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.md
Awesome Lists containing this project
README
# compose [![CI][ci-badge]][ci-link]
Compose a list of functions into a single function.
## Installation
```sh
$ component install ndhoule/compose
$ npm install @ndhoule/compose
```## API
### `compose(...funcs: Function)`
Creates a function that is the [composition](https://en.wikipedia.org/wiki/Function_composition) of a list of functions, where each function is passed the return value of the previous function.
Compose is right-associative, which means functions are called in right-to-left order. For example, the operation `h(g(f()))` is represented as `compose(h, g, f)`.
```javascript
var add = function(a, b) { return a + b; };
var square = function(x) { return x * x; };
var addThenSquare = compose(square, add);addThenSquare(1, 2); //=> 9
```## License
Released under the [MIT license](LICENSE.md).
[ci-link]: https://travis-ci.org/ndhoule/compose
[ci-badge]: https://travis-ci.org/ndhoule/compose.svg?branch=master