Generator
A generator is a language construct or computation that produces values incrementally on demand, typically suspending and resuming while preserving its state.
Secrets of the JavaScript Ninja, Second Edition
A JavaScript function that can yield values, suspend execution, and later resume with its local state preserved.
- How it is used
- Uses generators to produce values on demand, simplify traversal, and express dependent asynchronous tasks without blocking the UI.
- How deep it goes
- Explains syntax, iterator control, two-way communication, state transitions, and retained execution contexts through worked examples.
- Examples
- Demonstrates yielded strings, a local ID counter, recursive DOM traversal, and dependent JSON requests.
- What you can do after
- Build it from scratch with function*, yield, next(), and yield* to generate sequences and traverse a DOM tree.
Read how Secrets of the JavaScript Ninja, Second Edition explains generator →
Python Workout: 50 ten-minute exercises
A generator function is a Python function that produces a generator by yielding successive values while preserving its execution state between yields.
- How it is used
- Deploys generator functions to implement iterators, stream data, and avoid materializing large result collections.
- How deep it goes
- Explains yield, automatic completion, suspended execution, and retained locals, but defers generator expressions to a separate treatment.
- Examples
- Demonstrates small yielded sequences, directory-wide line streaming, elapsed-time reporting, chaining iterables, and memory-saving sums.
- What you can do after
- Build it from scratch as a stateful iterator that yields, filters, transforms, or augments values incrementally.
Read how Python Workout: 50 ten-minute exercises explains generator →
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
An iterator-like object returned by a generator function that controls resuming the generator and retrieving yielded values.
- How it is used
- Produces values on request and lets outside code resume execution or pass information back.
- How deep it goes
- Works through creation, pauses, two-way yields, and completion, then applies them to sequences without pursuing broader generator internals.
- Examples
- Uses infinite number and Fibonacci sequences, a feedback-driven simulation, and a timed game turn.
- What you can do after
- Build it from scratch: create generators that yield sequences, accept feedback through next(), or pause work between timed calls.
Python Workout, Second Edition
A generator function is a Python function containing yield that returns a generator object when called and resumes execution incrementally when iterated.
- How it is used
- Implements function-shaped iterators for incremental, filtered, transformed, or augmented data processing.
- How deep it goes
- Explains yield suspension, automatic termination, retained local state, and practical file and timing generators.
- Examples
- Uses line streaming across files, elapsed-time reporting, chaining iterables, filtering, and reimplementations of zip and range.
- What you can do after
- Build it from scratch as a lazy iterator that filters, modifies, combines, or supplements values from an iterable.
Read how Python Workout, Second Edition explains generator →
The Joy of JavaScript
A generator is a function or function-derived object in JavaScript that can produce a sequence of values over time and support iterator semantics.
- How it is used
- Uses generators to create iterables, model streams, process asynchronous chunks, and connect pull-based iteration with observables.
- How deep it goes
- Explains syntax, iterator results, yielding, async iteration, and stream integration, but does not develop generator runtime internals beyond suspended context.
- Examples
- Demonstrates yielded words, generated blockchain blocks, iterable validation branches, file-backed block streams, and observable pipelines.
- What you can do after
- Build generators and async generators, consume them with iteration syntax, and connect them to streamed data processing.
Python How-To
A generator is a Python construct that produces a sequence of values incrementally through iteration rather than computing the entire sequence at once.
- How it is used
- Supplies squares to `sum` and matching files to a processing loop without first building a list.
- How deep it goes
- Explains creation, `yield` resumption, exhaustion, generator expressions, and memory use; leaves generator-based coroutines as a legacy aside.
- Examples
- Uses a million-square sum, a partially consumed generator expression, a Fibonacci exercise, and matching `.dat` files.
- What you can do after
- Build it from scratch with `yield`, or apply a generator expression to supply values on demand.
Learn Haskell by Example
A generator is a list-comprehension clause that supplies values from a list or other sequence for subsequent comprehension clauses.
- How it is used
- Builds lists by supplying source values to comprehensions that transform and optionally filter them.
- How deep it goes
- Explains generator evaluation, guards, Cartesian products, and pattern matching without descending into implementation internals.
- Examples
- Uses numeric ranges, Cartesian products, word transformations, and Maybe-pattern filtering as concrete examples.
- What you can do after
- Builds filtered and combined lists with generators, guards, multiple sources, and matching patterns.
Functional Programming in JavaScript
A JavaScript function form that can pause and resume execution, yielding a sequence of values over time.
- How it is used
- Produces large, infinite, or asynchronously available data sequences incrementally through lazy iteration.
- How deep it goes
- Explains function* syntax, yield, saved execution context, iterators, composition, and traversal, without detailing iterator internals.
- Examples
- Uses range generation, bounded consumption, squared values, nested student generators, and recursive tree traversal.
- What you can do after
- Apply it via JavaScript generators to create, transform, consume, and compose lazy sequences.
Read how Functional Programming in JavaScript explains generator →
Fast Python: High performance techniques for large datasets
- How it is used
- Uses lazy generation to process large sequences with less memory and to avoid computing results that are never needed.
- How deep it goes
- Explains on-demand execution, yield-based iteration, and memory trade-offs, but does not detail generator internals.
- Examples
- Uses a CSV temperature reader and pandas chunks to demonstrate incremental processing.
- What you can do after
- Apply generators to process CSV values or data-frame chunks without first loading the complete result into memory.
Read how Fast Python: High performance techniques for large datasets explains generator →
Python Concurrency with asyncio
A generator is a Python iterator object that produces values lazily by suspending and resuming execution around yield points.
- How it is used
- Uses generators for memory-efficient lazy sequences and asynchronous production of values such as database rows.
- How deep it goes
- Explains creation, suspension, resumption, next, for, async for, and generator-based coroutines through runnable examples.
- Examples
- Demonstrates integer generators, delayed asynchronous integers, generator-based coroutines, and a custom future advanced by iteration.
- What you can do after
- Apply it via Python's next, for, async for, yield, and yield from constructs to produce values incrementally.
Read how Python Concurrency with asyncio explains generator →
Data Pipelines with Apache Airflow, Second Edition
A generator is a Python iterable that produces values incrementally rather than materializing them all at once.
- How it is used
- Uses lazy iteration to hide paginated API retrieval and support efficient existence checks in Airflow sensors.
- How deep it goes
- Explains generator creation with yield from, deferred page fetching, and StopIteration handling without covering generator internals.
- Examples
- Demonstrates paginated MovieLens ratings retrieval and a sensor that tests for one available record.
- What you can do after
- Apply it via Python generators to stream paginated API records or test whether a result exists without fetching everything.
Read how Data Pipelines with Apache Airflow, Second Edition explains generator →
Practices of the Python Pro
A generator is a Python construct that produces a sequence of values incrementally while preserving its execution state between requests.
- How it is used
- Reduces memory usage when iterating over values that do not need to exist simultaneously.
- How deep it goes
- Defines incremental production, explains yield-based pausing, and demonstrates a range-like implementation.
- Examples
- Uses range-like counting, squared-number generation, and chained generators to illustrate incremental computation and memory use.
- What you can do after
- Build it from scratch with yield-based loops and choose it over lists when all results are not needed at once.
Related concepts
- yielduses · A language construct that yields control from a computation, optionally passing a value to another context, and may allow the suspended computation to continue later.
- functionkind of · A function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
- iteratorkind of · An iterator is an object or abstraction that provides successive values from a sequence or data source through a traversal protocol.
- nextused by · An iterator operation that advances an iterator and returns its next value or result, with behavior on exhaustion determined by the API.
- iterablekind of · An iterable is an object or value that provides or supports a protocol for producing its elements sequentially.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.











