Skip to content

Instantly share code, notes, and snippets.

@nmccready
Created July 29, 2021 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmccready/8618c3485af06f48ffb505d9c78744f9 to your computer and use it in GitHub Desktop.
Save nmccready/8618c3485af06f48ffb505d9c78744f9 to your computer and use it in GitHub Desktop.
Promise Map Anything
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