Generators (function*) Playground

The neighbourhood head’s night patrol is a generator: what has run once g = ronda() is called, how far does the neighbourhood head walk each time Dina strikes…

Why it matters

Generators make lazy or endless sequences (IDs, streams, pagination), compact custom iterators, and are the base of async iterators for streaming. Understanding "pause and resume" opens patterns plain functions cannot easily copy.

The key idea

A generator stops at every yield and only goes on when pulled

Common mistakes

Try it in this playground