proposal-iterator-helpers icon indicating copy to clipboard operation
proposal-iterator-helpers copied to clipboard

taking Infinity or dropping 0

Open michaelficarra opened this issue 2 years ago • 1 comments

Should iter.take(Infinity) or iter.drop(0) return iter instead of wrapping it unnecessarily?

michaelficarra avatar Aug 12 '22 17:08 michaelficarra

I would lean towards wrapping, for consistency. It's weird for the identity to depend on the precise value of an argument like this, and I can imagine code along the lines of

let next = Iterator.HelperPrototype.next;
[...]
let skipped = base.drop(n);
[...]
next.call(skipped);

which would break if it happened to hit one of the special cases.

bakkot avatar Aug 12 '22 17:08 bakkot

Not totally convinced on this one, but I will admit it's unusual. Closing.

michaelficarra avatar Aug 26 '22 18:08 michaelficarra