2. www.luxoft.com
ES6 introduced a new way of working with
functions and iterators in the form of Generators
(or generator functions).
A generator is a function that can stop
midway and then continue from where it
stopped.
In short, a generator appears to be a function
but it behaves like an iterator.
What is a generator?
6. www.luxoft.com
What is an iterator?
interface iteratorResult {
done: boolean,
value: any
}
Iterator is a way to pull data from a data structure on one-at-a-time fashion, it needs to
implement the iterator interface (which has three methods - next(), return() and
throw()).
An iteratorResult that returns from the iterator next() method needs to follow this
interface:
So each time we call next() on an iterator we should get {value: the current
iteration value, done: false/true}