https://github.com/raineorshine/reduce-promises
Serially executes promise-returning functions and reduces the results with the given accumulator.
https://github.com/raineorshine/reduce-promises
Last synced: 3 months ago
JSON representation
Serially executes promise-returning functions and reduces the results with the given accumulator.
- Host: GitHub
- URL: https://github.com/raineorshine/reduce-promises
- Owner: raineorshine
- License: isc
- Created: 2017-04-06T22:03:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-06T22:05:26.000Z (about 8 years ago)
- Last Synced: 2025-03-10T15:09:32.845Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reduce-promises
[](https://npmjs.org/package/reduce-promises)
[](https://travis-ci.org/raineorshine/reduce-promises)Serially executes promise-returning functions and reduces the results with the given accumulator.
## Install
```sh
$ npm install --save reduce-promises
```## Usage
```js
const { reducePromises, accumulate } = require('reduce-promises')const functions = [
() => Bluebird.delay(100, 'a'),
() => Bluebird.delay(5, 'b'),
() => Bluebird.delay(20, 'c')
]
reducePromises(functions, _.concat, []) // ['a', 'b', 'c']
```The above concat reduction is common enough to warrant a shorthand function.
```
const functions = [
() => Bluebird.delay(100, 'a'),
() => Bluebird.delay(5, 'b'),
() => Bluebird.delay(20, 'c')
]
accumulate(functions) // ['a', 'b', 'c']
```## License
ISC © [Raine Revere](https://github.com/raineorshine)