Skip to content

Instantly share code, notes, and snippets.

@nmccready
Created July 29, 2021 19:15
Show Gist options
  • Save nmccready/8618c3485af06f48ffb505d9c78744f9 to your computer and use it in GitHub Desktop.
Save nmccready/8618c3485af06f48ffb505d9c78744f9 to your computer and use it in GitHub Desktop.

Revisions

  1. nmccready created this gist Jul 29, 2021.
    10 changes: 10 additions & 0 deletions promiseMapAnything.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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)));
    })
    );