/promise-array-helpers

Some helpers to work with promises and arrays in JS

Primary LanguageJavaScriptMIT LicenseMIT

promise-array-helpers

A collection of functions to make it easier to work with Arrays and Promises together.

Installing

npm install --save promise-array-helpers

or

yarn add promise-array-helpers

Included Functions

The available function are: pmap, preduce, pfilter, pforEach, papply, pevery and psome. They are supposed to work exatcly like their conterparties, but treating values and promise equaly. And in the end returning an Promise with the result of the operation.

Examples

const list = [1, 2, Promise.resolve(3), Promise.resolve(4)]
pmap(list, (item) => item + 1) // Returns Promise<[2, 3, 4, 5]>
const list = [Promise.resolve(3), Promise.resolve(4)]
pfilter(list, (item) => (item % 2) === 1) // Returns Promise<[3]>
const list = [1, 2, Promise.resolve(3), Promise.resolve(4)]
preduce(list, 0, (acc, item) => acc + item) // Returns Promise<10>

License

MIT