Open danprince opened 8 years ago
This should be possible with a symbol polyfill, allowing each function to return an iterator which would be respected by for..of
, ...
, etc.
Functions that generate iterators in non-ES6 environments can use "@@iterator"
as a Symbol.iterator
polyfill. All functions will check alternative strategies before dropping back to using iterators. This should allow lazy/iterators to be added to main namespace.
It'd be great to have a
zaphod/lazy
interface that exposed functions that worked lazily with iterables.In this example
range()
returns an iterator which yields an infinite range of numbers. Map returns another iterator which requests values from range, appliesf
to them, then yields them to take.