0.1.0 • Published 6 years ago
promise-array-helpers v0.1.0
promise-array-helpers
A collection of functions to make it easier to work with Arrays and Promises together.
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>
0.1.0
6 years ago