Skip to main content

Module iterator

Module iterator 

Source
Expand description

Iterator helpers (27.1.4) — map, filter, take, drop, flatMap and the terminal reduce/toArray/forEach/some/every/find, plus the Iterator constructor and Iterator.from.

None of it existed: [1,2,3].values().map(f) was “map is not a function”.

The helpers are LAZY, which is the whole point of them — take(3) on an endless generator has to stop after three pulls, not materialise anything. Each is an @@native = "IteratorHelper" object holding the iterator it draws from, so a chain is a chain of pulls; only the terminal operations drain. That also makes them work over any iterator, including a user object with a next method.

Constants§

LAZY
The lazy helpers, which return another iterator.
METHODS
Everything Iterator.prototype carries, so any iterator answers for it.
STATIC_METHODS
Iterator’s own statics.
TERMINAL
The terminal operations, which drain the iterator and return a value.

Functions§

call
Dispatch a helper called on the iterator recv.
done_step
The { value: undefined, done: true } an exhausted iterator reports.
helper_next
One step of a lazy helper: pull from the source until this stage produces a value or the source runs out.
helper_return
Mark a helper exhausted and close whatever it was drawing from — a return on any stage of a chain has to reach the generator at the bottom of it.
is_helper
True if name is one of the helper methods (lazy or terminal).
static_call
Iterator.from(x).