-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmapAsync.js
More file actions
26 lines (23 loc) · 723 Bytes
/
mapAsync.js
File metadata and controls
26 lines (23 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const { resolveArgs } = require('./internals/resolveArgs')
const { unCurry } = require('./internals/unCurry')
const mapAsync = callback => collection => Promise
.resolve(collection)
.then(resolvedCollection => Promise.all(resolvedCollection.map(
resolveArgs(callback),
)))
/**
* @callback iteratee
* @async
* @param {*} element - The current element in the collection.
* @param {number} [index] - The index of the current element in the collection.
* @param {*[]} [collection] - The collection.
* @return {Promise<*>}
*/
/**
* @async
* @function mapAsync
* @param {iteratee} callback
* @param {*[]|Promise<*[]>} collection
* @return {Promise<*[]>}
*/
module.exports.default = unCurry(mapAsync, 2)