https://github.com/fabiosantoscode/add-functions
Add two functions together and choose when the original one gets called!
https://github.com/fabiosantoscode/add-functions
Last synced: 10 months ago
JSON representation
Add two functions together and choose when the original one gets called!
- Host: GitHub
- URL: https://github.com/fabiosantoscode/add-functions
- Owner: fabiosantoscode
- License: mit
- Created: 2018-10-08T14:25:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-24T15:33:10.000Z (over 7 years ago)
- Last Synced: 2025-03-11T13:41:39.997Z (11 months ago)
- Language: JavaScript
- Size: 267 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# add-functions
[](https://travis-ci.org/fabiosantoscode/add-functions) [](https://coveralls.io/github/fabiosantoscode/add-functions)
Add two functions together and choose when the original one gets called!
# require('add-functions')(a, (callOriginal) => { callOriginal(); foo()})
Adds one or more functions together. Functions will take an additional callOriginal argument. This function will call the function before yours in the added functions.
```javascript
const a = n => n + 1
const b = (n, callPrevious) => n + callPrevious() + 1
const c = addFunctions(a, b)
c(0) // -> 2
```
```javascript
const asynchronouslyAdd2 = addFunctions(
() => getPromise(),
previous => previous().then(p => p + 1),
previous => previous().then(p => p + 1),
)
```