1 of 10

Iterator Sequencing

for Stage 2

Michael Ficarra • June 2024

2 of 10

reminder: goals

  • conveniently compose 2 iterators
  • conveniently compose 0 or more iterators
  • compose an infinite sequence of iterators
  • conveniently interleave other values among the iterators
  • discoverable, familiar pattern

3 of 10

solution space considered

  • variadic Iterator.from(...iterators)
  • Iterator.prototype.flat()
  • Iterator.prototype.append(...iterators)
  • Iterator.concat(iteratorOfIterators)
  • Iterator.concat(...iterators)

4 of 10

previous strategy

  • variadic Iterator.from
    • for when you have a small number of iterators/iterables
  • Iterator.prototype.flat
    • for when you have an iterator/iterable of iterators/iterables

feedback:

  • because of an optimisation in Iterator.from, the 1-arg case is observably slightly different than 0 or 2+ args
  • questions about optimisability of Iterator.prototype.flat
  • unclear whether infinite iterators of iterators are common enough to motivate flat
  • unclear who is responsible for closing iterators produced by the target of flat, or how that would work when infinitely many may be produced

5 of 10

new goals

  • conveniently compose 2 iterators
  • conveniently compose 0 or more iterators
  • compose an infinite sequence of iterators
  • conveniently interleave other values among the iterators
  • discoverable, familiar pattern
  • no observable difference between 1-iterator case and 0+ iterators

6 of 10

Iterator.concat(...iterators)

  • conveniently compose 2 iterators
  • conveniently compose 0 or more iterators
  • conveniently interleave other values among the iterators (using [] wrapper)
  • discoverable, intuitive pattern
  • no observable difference between 1-iterator case and 0+ iterators

  • JHD doesn't like the name "concat" for this

7 of 10

name alternatives (in champion preference order)

  • concat
  • concatenate
  • sequence
  • join
  • combine
  • fuse
  • cat
  • chain

8 of 10

full spec text

9 of 10

polyfill & basic tests

10 of 10

Stage 2?

assign reviewers?