What does HackerNews think of proposal-iterator-helpers?
Methods for working with iterators in ECMAScript
In the olden days, I feel like the codebases I worked on needed to use .apply() multiple times a week, to figure out some creative way of invoking functions. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... That's all gone now; I'd take even odds that 50% of my team knows .call and .apply.
Chrome 117 is shipping Object.groupBy() and that's gonna be a huge help in eliminating a lot of the last places we end up using lodash. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
But it's not going to help all that much with this problem. The iterator protocol in JS involves an allocation for every individual value, and while in some cases that can be optimized out, it's pretty tricky to completely optimize.
It's always going to be difficult to beat a c-style for loop for performance.
That's W3C’s job, not ECMA’s.
> Where are all the containers?
?
> Sorted sets/maps?
Sets and Maps are sorted (by insertion order)
> Why can't I even map an iterator?
It's coming, but someone will likely be exhausted by that addition. https://github.com/tc39/proposal-iterator-helpers
[1]: https://github.com/tc39/proposals/blob/master/stage-1-propos...
[2]: https://github.com/tc39/proposal-iterator-helpers
[3]: https://github.com/tc39/notes/blob/master/meetings/2019-06/j...
no thanks, I don't think it's an interesting feature, there are alternatives (chaining, promises, ..) to avoid the cost of this new syntax
Other proposals I'm more excited about:
- https://github.com/tc39/proposal-iterator-helpers
- https://github.com/tc39/proposal-slice-notation/ (and https://github.com/tc39/proposal-slice-notation/pull/32)
I don't understand your `+0.5`, I've written below the transcription for your description
[...1:30].map(a =>
[...a+1:30].filter(b => gcd(a,b)==1).map(b =>
[...b+1:30].filter(c => gcd(a,c)==1
&& gcd(b,c)==1
&& Number.isInteger((a**3+b**3+c**3)**(1/3))
.map(c => [a, b, c])
)
).flat(2)
Or another equivalent way: [...1:30].flatMap(a =>
[...a+1:30].filter(b => gcd(a,b)==1).flatMap(b =>
[...b+1:30].filter(c => gcd(a,c)==1
&& gcd(b,c)==1
&& Number.isInteger((a**3+b**3+c**3)**(1/3)))
.flatMap(c => [[a, b, c]])
Or another way (generating first all the triples): [...1:30].flatMap(a => [...a+1:30].flatMap(b => [...b+1:30].flatMap(c => [[a, b, c]])))
.filter(([a, b, c]) => gcd(a,b)==1 && gcd(a,c)==1
&& gcd(b,c)==1 && Number.isInteger((a**3+b**3+c**3)**(1/3)))
with https://github.com/tc39/proposal-iterator-helpers, which would allow lazy evaluation, and make more sense than above (1:30).flatMap(a => (a+1:30).flatMap(b => (b+1:30).flatMap(c => [[a, b, c]])))
.filter(([a, b, c]) => gcd(a,b)==1 && gcd(a,c)==1
&& gcd(b,c)==1 && Number.isInteger((a**3+b**3+c**3)**(1/3)))
without the slice-notation, it's really ugly (hence the proposal in the first link) Array.from({length: 30},(_,a)=>a+1)
.flatMap(a=>Array.from({length: 30-a-1},(_,b)=>a+b+1)
.flatMap(b => Array.from({length: 30-b-1},(_,c)=>b+c+1).flatMap(c => [[a, b, c]])))
.filter(([a, b, c]) => gcd(a,b)==1 && gcd(a,c)==1
&& gcd(b,c)==1 && Number.isInteger((a**3+b**3+c**3)**(1/3)))