question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: allow .each to accept objects

See original GitHub issue

Libraries like Underscore and Lodash have implementations of each which accept both arrays and objects as parameters, calling the provided function with (value, idx) or (value, key) depending on the input type.

This could be a useful extension to bluebird, saving having to do:

something().then(_.pairs).then(([k, v] => ...)

Or the equivalent with non-es6 functions.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NotBobTheBuildercommented, Aug 24, 2016

Yes, you can - but also remember that this would happen part way through a Promise chain, so your suggestion would look like:

getMapFromAPI().then(object => {
   const keys = Object.keys(object);
   Promise.each(keys, (key) => {
    something( keyPair[key])
   })
})

But with my suggestion, that would be

getMapFromAPI().each((data, key) => something(data))

Which is significantly more composable.

Given that Arrays are subclasses of objects (string keys mapped to values) it makes sense IMO to “genericise” this method up to objects rather than to have to create whole new lower-level strategies for writing this type of iteration code.

0reactions
petkaantonovcommented, Aug 25, 2016

If you’re using lodash you can do

getMapFromApi().then(_).call("forEach", function() {

});

Instead of having us slowly implement every method of lodash in bluebird

(if some property values are promises, do .props().then(_)...

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Handle Feature Requests - The Ultimate Guide for ...
How to track and manage feature requests in an organized and systematic way, all leading to better product execution.
Read more >
Allow Breadcrumb data to accept objects as values · Issue #88 ...
I think this could be a feature request opened on Sentry and if implemented, change the SDKs which is a coordinated thing now...
Read more >
Feature Requests: Hot (424 ideas) – Horizon Worlds
If a similar idea already exists, you can support and comment on it. If it doesn't exist, you can post your idea so...
Read more >
Feature requests - Please read before requesting something
If I have multiple objects (e.g. fields) selected going across the page, I would love to have an "Equal Horizontal" feature that would...
Read more >
Product Feature Requests - How to Write and Submit Them
Describes the Feature Request process and provides tips on how to write a Feature Request for best results.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found