Please enable JavaScript.
Coggle requires JavaScript to display documents.
Generators, advanced iteration - Coggle Diagram
Generators, advanced iteration
Generators
Generator functions
To create a generator, we need a special syntax construct: function*, so-called “generator function”.
When such function is called, it doesn’t run its code. Instead it returns a special object, called “generator object”, to manage the execution.
-
-
Generators are iterable
-
As generators are iterable, we can call all related functionality, e.g. the spread syntax ...
-
Generator composition
Generator composition is a special feature of generators that allows to transparently “embed” generators in each other.
-
-
generator.throw
To pass an error into a yield, we should call generator.throw(err). In that case, the err is thrown in the line with that yield.
generator.return
-
If we again use generator.return() in a completed generator, it will return that value again
-