What Is a Generator?
A generator is a special function that yields values one at a time, suspending its execution after each yield and resuming where it left off when the next value is requested. It keeps its local state across these pauses without building the whole result in memory. Generators are a convenient way to express lazy, on-demand sequences.
Why it matters
Producing values lazily lets a generator handle large or even infinite sequences with constant memory. It cleanly separates how items are produced from how a consumer iterates over them.
Related guides
What Is an Iterator Protocol?An iterator protocol is the standard interface a type implements to be traversed element by element, typicall…
What Is Lazy Evaluation?Lazy evaluation delays computing an expression until its value is actually needed, and may skip it entirely i…
What Is a Continuation?A continuation represents the rest of a computation at a given point, as a value that can be invoked later to…