4 ms·
The fast code eventually looks like: myIterator(value => { total += value; }); And most people would say this isn't really an iterator in Java
by kccqzy 1y ago
The fast code eventually looks like:
myIterator(value => {
total += value;
});
And most people would say this isn't really an iterator in JavaScript any more. This is more like a forEach function. And herein lies the rub: this callback style iteration used to be called internal iterators; the kind of normal iterators shown by the author and also in languages like Rust used to be called external iterators. Eventually people stopped referring to the former style as iterator and I think that's a good terminology change: the internal/external distinction isn't immediately understandable, and it's better to call it a forEach function.
I think early Rust even supported the internal iterator style but they abandoned it because IIRC they found external iterations more performant, which is the exact opposite case here.