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

fixes #207: add a counter parameter to Array analogues that have indices

Open michaelficarra opened this issue 2 years ago • 7 comments

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.

michaelficarra avatar Aug 09 '22 15:08 michaelficarra

The PR does what it claims to do, but I'm even less enthusiastic about it than "unconvinced".

ljharb avatar Aug 09 '22 18:08 ljharb

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).

rbuckton avatar Sep 06 '22 19:09 rbuckton

I am currently leaning toward merging this. If I don't receive any further feedback soon, we will accept this change.

michaelficarra avatar Sep 26 '22 21:09 michaelficarra

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 */ }

zloirock avatar Sep 26 '22 23:09 zloirock

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 avatar Sep 27 '22 00:09 bakkot

@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 avatar Sep 27 '22 00:09 zloirock

@zloirock This change was discussed during 2 plenary sessions (July and September) and each time it received weak mixed feedback from delegates.

michaelficarra avatar Sep 27 '22 00:09 michaelficarra

for (let [value, index] of iter.map(Array)) {
  /* some complex logic */
}

luncheon avatar Dec 10 '22 01:12 luncheon