Created
July 29, 2021 19:15
-
-
Save nmccready/8618c3485af06f48ffb505d9c78744f9 to your computer and use it in GitHub Desktop.
Promise Map Anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PromiseMapAnything = (promises, cb) => | |
Promise.try(() => | |
Promise.resolve(promises).then((arrayOrObject) => { | |
if (_.isArray(arrayOrObject)) { | |
return Promise.map(arrayOrObject, cb); | |
} | |
const size = Object.values(arrayOrObject).length; | |
return Promise.all(_.map(arrayOrObject, (value, key) => cb(value, key, size))); | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment