proposal-iterator-helpers
proposal-iterator-helpers copied to clipboard
fixes #207: add a counter parameter to Array analogues that have indices
Fixes #207. Adds "counter" parameters to callbacks of methods that have an Array.prototype
analogue that passes an index to its callback. Also removes .indexed()
now that it's equivalent to .map((a, i) => [i, a])
.
Feedback on #207 has been mixed. I am not yet convinced that this is an improvement, but I am also not opposed to this change if that's what the committee decides.
The PR does what it claims to do, but I'm even less enthusiastic about it than "unconvinced".
I'm very much in favor of this as it reduces the complexity of refactoring something like array.map((item, index) => ...)
to iter.map((item, index) => ...)
, or array.map(existingMapFn)
to iter.map(existingMapFn)
.
I am currently leaning toward merging this. If I don't receive any further feedback soon, we will accept this change.
It looks like the feedback from #207 is rather against this.
BTW I don't understand why it also removes .indexed()
method. Iterators and indexes can be used not only in affected helpers. How do you propose to replace something like this?
for (let [counter, value] of customGenerator().indexed()) { /* some complex logic */ }
It looks like the feedback from https://github.com/tc39/proposal-iterator-helpers/issues/207 is rather against this.
I see three people who have expressed opposition (you, @ljharb
, and @bergus
), and three who have expressed support (me, @js-choi
, and @rbuckton
) (plus two users who just +1'd things, one in each direction). I would not summarize that as "rather against this".
@bakkot @rbuckton
was not in #207 - so #207 is rather against this. Anyway, 50 / 50 is not a reason to merge it.
I'm against indexes param, but not strongly against - it's inconsistency, but useful in some cases. However, I'm strongly against removing the .indexed()
helper.
@zloirock This change was discussed during 2 plenary sessions (July and September) and each time it received weak mixed feedback from delegates.
for (let [value, index] of iter.map(Array)) {
/* some complex logic */
}