4 ms·
Is there any chance javascript will get comprehensions (array, set, map, generator)? I know there was a proposal a few years ago that didn't go forwards.
by da39a3ee 5y ago
Is there any chance javascript will get comprehensions (array, set, map, generator)? I know there was a proposal a few years ago that didn't go forwards.
- hajile 5y agoIt seems fairly unlikely to me at this point. Instead, you'll be told to do something like this [...foo.filter(x => x % 2 === 0)] rather than [foo | where x % 2 === 0]
- da39a3ee 5y agoApart from the arguable syntactic attractions, does it not bother people that chained maps/filters traverse the iterable multiple times, whereas comprehensions would give the language a chance to compile a complex comprehension down to a single traversal?
- hajile 5y agoThey need to add iterator versions of the built-ins. At that point, not only this, but a ton of other efficiency issues go away. At present, chaining lodash functions together will integrate once, so I’d recommend using them to save time and memory.