1 of 9

Iterator Methods

Update + Stage 2

2 of 9

Refresher

3 of 9

Refresher

4 of 9

Refresher

5 of 9

What we have now

  • map
  • filter
  • take
  • drop
  • asIndexedPairs*
  • reduce
  • collect
  • forEach
  • some
  • every
  • find
  • Array methods
  • Bounding infinite iterators
  • Array <-> Iterator

6 of 9

asIndexedPairs naming

  • Known as enumerate in most iteration APIs
  • Introduces a counter from the point it is called
  • Name bikeshedding
    • enumerate, withIndex, asIndexedPairs, toIndexedPairs, etc

7 of 9

Design FAQ

  • Why on iterator instead of iterable
    • Iterators are already their own interface with a prototype we can add methods to
    • Calling a generator (syntactic iteration primitive) returns an iterator
    • array.forEach, map.forEach, etc already taken
  • Why methods instead of functional application
    • Consistent design with JS in general, and the JS list primitive (array)
  • thisArg
    • Common case is arrow functions
    • it.map(f.bind(thisArg)) is more explicit than it.map(f, thisArg)

8 of 9

How to specify async generators

9 of 9

Stage 2?