Generator functions
If function (or method) contains one or more
yield
statements it is called generator.
When called, generator function does not evalute its statements,
instead, it returns generator enumeration of type
anvil.lang.enumeration.
The body of generator function is executed when ``next()ยดยด method is
called or, in general, when more elements is retrieved from enumeration.
Execution continues until one of the three conditions are met
- Yield statement is encountered: its contained expression is evaluated
and returned as a next value from enumeration.
State of generator is frozen; local variables and parameters are saved and when next
element is retrieved execution continues right after the yield statement.
- Return statement is encountered:
return value is discarded and generator terminates and will
produce no more values.
- End of function is reached: Generator terminates and will
produce no more values.
Only one thread at a time may call generator.
Add a note
|