Generating Generators
summary
Implements Python‑style generators for Go by static analysis and code generation: the tool gengen takes functions using a fake yield and emits real Go closures plus a state block, labels and gotos, and a genjen build tag with go:generate so generated code compiles separately. It hoists variable declarations to the state struct, converts blocks to labeled jumps, adapts maps/slices/channels, and runs — demo builds a Fibonacci generator that produces correct values.
AI-written summary · about
chapters (8)
- 0:00Introduction and context
- 1:38The problem of iterators
- 4:10Implementing iterators in Go
- 7:38Introducing generators
- 10:54Building a generator tool
- 12:16Control flow transformations
- 17:35Modeling control structures
- 20:49Fibonacci demo and conclusion
related talks
30mWrite Less (Code), Generate More
27mInception: Go programs that generate Go code
51mCode generation tips you didn't ask for
16mTools for working with Go Code
51mBuilding Generative AI Applications in Go- Gari Singh, Google (Part 2)
01h 12mC# Source Generators in Action
01h 04mAn Introduction to Functional Programming in Go
16mGo Generics
