You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This IMHO would be much easier to use, and it would have benefits that extend beyond iteration, too.
If it doesn't have a .reversed method, it isn't reversible. I consider that far more intuitive than this proposal.
Arrays could implement this to return not merely an iterator, but an array. And this of course is just generally more useful, and for cases like .slice().reverse(), would provide a significant performance boost as you can use SIMD instructions to copy it in chunks. (In my experience, in perf-sensitive places, you're probably already writing a for loop anyways if you want reverse iteration, and if you really want a reverse iterator, you can just do .values().reversed(), .entries().reversed(), and so on like you'd likely already do with maps and sets.)
Adding it to iterable iterators alongside .next() would fit with the simple non-symbol name better, and one could imagine it being initialized with shared state.
The text was updated successfully, but these errors were encountered:
dead-claudia
changed the title
Why not just make an iter.reversed(): Iterable<T> protocol and skip on the new symbol?
Why not just make an iterable.reversed(): Iterable<T> protocol and skip on the new symbol?
Nov 23, 2020
And as this isn't going to be adding additional language semantics that use.reversed(), I don't see any risk of conflict here unless, say, someone somewhere is defining an incompatible version of Array.prototype.reversed or something.
dead-claudia
changed the title
Why not just make an iterable.reversed(): Iterable<T> protocol and skip on the new symbol?
Why not just add iterable.reversed(): Iterable<T> to the iterable protocol and skip on the new symbol?
Nov 23, 2020
This IMHO would be much easier to use, and it would have benefits that extend beyond iteration, too.
.reversed
method, it isn't reversible. I consider that far more intuitive than this proposal..slice().reverse()
, would provide a significant performance boost as you can use SIMD instructions to copy it in chunks. (In my experience, in perf-sensitive places, you're probably already writing afor
loop anyways if you want reverse iteration, and if you really want a reverse iterator, you can just do.values().reversed()
,.entries().reversed()
, and so on like you'd likely already do with maps and sets.).next()
would fit with the simple non-symbol name better, and one could imagine it being initialized with shared state.The text was updated successfully, but these errors were encountered: