Lazy evaluation
Lazy evaluation is an evaluation strategy that defers computing an expression until its value is needed, potentially avoiding the computation entirely.
Functional Programming in Scala, Second Edition
Lazy evaluation defers evaluating an expression until its value is required.
- How it is used
- Uses lazy lists to fuse transformations, avoid unnecessary work, and separate computation descriptions from their evaluation.
- How deep it goes
- Defines thunks, forcing, memoization, and by-name parameters, then develops lazy-list operations and parser-combinator nonstrictness.
- Examples
- Traces chained List and LazyList transformations; implements exists, take, map, filter, infinite streams, unfold, and parser many.
- What you can do after
- Build it from scratch with thunk-backed LazyList constructors and apply nonstrict folds to stop traversal early.
Read how Functional Programming in Scala, Second Edition explains lazy evaluation →
Fast Python: High performance techniques for large datasets
- How it is used
- Uses deferred computation to process large datasets with smaller memory footprints and build data pipelines.
- How deep it goes
- Explains generators and Dask task graphs through worked implementations, including eager operations and memory trade-offs.
- Examples
- Uses a CSV temperature generator, a Dask property-tax calculation, and a range-versus-list timing comparison.
- What you can do after
- Apply lazy evaluation with Python generators and Dask, and evaluate when materialization or eager execution changes the cost.
Read how Fast Python: High performance techniques for large datasets explains lazy evaluation →
Functional Programming in C#, Second Edition
A lazy computation is a computation whose work and result are deferred until needed.
- How it is used
- Uses laziness to avoid unnecessary work and compose computations before execution.
- How deep it goes
- Defines deferral and implements lazy arguments, Option fallbacks, Map, and Bind.
- Examples
- Demonstrates random selection between computations and a cache lookup with a deferred database fallback.
- What you can do after
- Apply lazy evaluation in C# using Func<T> arguments and compose deferred computations with Map and Bind.
Read how Functional Programming in C#, Second Edition explains lazy evaluation →
Tiny Python Projects: Learn coding and testing with puzzles and games
A lazy function defers producing a result until that result is needed.
- How it is used
- Uses deferred iteration for ranges, reverse sequences, mapped values, and filtered elements consumed by loops or other operations.
- How deep it goes
- Defines deferral and demonstrates materialization with list(), but stops short of implementation internals.
- Examples
- Demonstrates character indexes, reverse counting, consonant filtering, car selection, and vowel replacement.
- What you can do after
- Apply it via Python's list(), loops, join(), map(), and filter() to control when iterable results are produced.
Functional Programming in JavaScript
An evaluation strategy that delays computing an expression until its value is required.
- How it is used
- Optimizes functional JavaScript by deferring unnecessary computations, especially when processing large inputs or selecting subsets.
- How deep it goes
- Explains eager-versus-lazy execution, conditional deferral, alternation, and Lodash shortcut fusion, but does not develop language-level lazy evaluation internals.
- Examples
- Uses range with take, Maybe with a fallback, student lookup, Lodash chains, and an enrollment-average pipeline.
- What you can do after
- Apply it via Lodash chains and functional combinators to defer unused work and limit processing to requested results.
Read how Functional Programming in JavaScript explains lazy evaluation →
Software Engineering for Data Scientists
Lazy evaluation is an evaluation strategy in which an expression is computed only when its result is required or evaluation is explicitly requested.
- How it is used
- Supports large-scale data processing and exploratory analysis without immediately computing each transformation.
- How deep it goes
- Defines deferred execution and demonstrates explicit evaluation through Dask compute() and PySpark collect() or show().
- Examples
- Uses an ads dataset for deferred reads, filtering, click-rate groupbys, descriptive statistics, and category counts.
- What you can do after
- Apply it via Dask or PySpark by composing transformations and invoking compute(), collect(), or show() when results are needed.
Read how Software Engineering for Data Scientists explains lazy evaluation →
Systems Programming with Zig
Lazy evaluation is an evaluation strategy that delays computing an expression until its value is needed.
- How it is used
- Enables target-specific Zig implementations without evaluating unused platform branches.
- How deep it goes
- Defines lazy evaluation and explains its compiler trade-off through target selection and a validation caveat, without detailing compiler internals.
- Examples
- Uses a parsed wordlist logged at compile time and a Linux-versus-Windows function branch.
- What you can do after
- Diagnose/debug comptime code with @compileLog to force evaluation and inspect a value.
Read how Systems Programming with Zig explains lazy evaluation →
Kotlin in Action, 2E
Lazy evaluation postpones computation until a result is required and can stop processing once that result is obtained.
- How it is used
- Uses Kotlin sequences to execute collection-operation chains efficiently without storing intermediate collections.
- How deep it goes
- Explains intermediate and terminal operations, evaluation order, short-circuiting, and filter placement, stopping short of implementation internals.
- Examples
- Demonstrates asSequence pipelines, observable map and filter execution, toList triggering, and find stopping after a matching result.
- What you can do after
- Apply it via Kotlin sequences to reduce intermediate collections and avoid unnecessary element processing.
Learn Haskell by Example
Lazy evaluation delays evaluating an expression until its value is required.
- How it is used
- Uses deferred computation to avoid unnecessary work during graph search and other data-processing operations.
- How deep it goes
- Explains forcing, discarded arguments, lazy data structures, performance trade-offs, and strict alternatives without detailing runtime implementation.
- Examples
- Demonstrates `const` with an enormous integer, incremental ladder-game graph construction, and lazy versus strict folds.
- What you can do after
- Evaluate when laziness avoids work, select lazy structures for searches, and diagnose memory risks using strict folds or StrictData.
Read how Learn Haskell by Example explains lazy evaluation →
The Well-Grounded Rubyist, Fourth Edition
Lazy evaluation defers producing results until they are requested rather than materializing all results in advance.
- How it is used
- Uses lazy enumerators to process large or infinite sequences while requesting only the results a downstream operation needs.
- How deep it goes
- Explains enumerator mechanics, lazy chaining, infinite ranges, finite prefixes, and recursive aggregation through executable examples.
- Examples
- Demonstrates paired animal slices, infinite multiples, square sequences, and recursive powers-factorial summation.
- What you can do after
- Apply it via Ruby lazy enumerators to filter, map, and consume finite prefixes of large or infinite sequences.
Read how The Well-Grounded Rubyist, Fourth Edition explains lazy evaluation →
Snowflake Data Engineering
Lazy execution is an evaluation strategy that postpones running data operations until a triggering operation requires their results.
- How it is used
- Uses deferred Snowpark data-frame execution to batch pipeline operations before inspection or persistence.
- How deep it goes
- Explains execution triggers, batching, and client-transfer effects, but does not detail internal query planning.
- Examples
- Demonstrates holiday_flags, collect(), DIM_DATE, and save_as_table("DIM_DATE") in a Snowpark pipeline.
- What you can do after
- Apply it via Snowpark by batching data-frame operations and triggering execution with collect(), count(), show(), or save_as_table().
Read how Snowflake Data Engineering explains lazy evaluation →
Python How-To
Lazy evaluation is an evaluation strategy in which an operation or value is computed only when its result is needed.
- How it is used
- Uses deferred computation to reduce unnecessary processing and memory use in generators and class attributes.
- How deep it goes
- Explains on-demand generator state and cached property loading, stopping short of broader language-specific implementation details.
- Examples
- Demonstrates perfect-square generators and User follower profiles loaded from a remote server.
- What you can do after
- Apply it via Python generators and properties to defer expensive work and retain results after first access.
Object-Oriented Software Design in C++
The Lazy Evaluation Principle is a design principle that delays an expensive calculation until its result is needed.
- How it is used
- Improves runtime performance by deferring expensive date conversions until getters or arithmetic require their results.
- How deep it goes
- Defines the principle and demonstrates synchronized representations, validity flags, and demand-triggered conversion; it stops short of general algorithms.
- Examples
- Uses a Date class that converts between calendar fields and Julian day numbers only when access or arithmetic requires synchronization.
- What you can do after
- Apply lazy evaluation by tracking representation validity and validating each representation immediately before its use.
Read how Object-Oriented Software Design in C++ explains lazy evaluation →
Idiomatic Rust
Lazy evaluation is an execution strategy that postpones computing an expression until its result is required.
- How it is used
- Uses lazy evaluation to defer iterator transformations until a collection or other operation requires their results.
- How deep it goes
- Explains that map returns another iterator and collect forces evaluation, without detailing iterator internals.
- Examples
- Demonstrates converting array integers to strings with map and collect.
- What you can do after
- Apply lazy transformations with Rust iterator methods such as map, then force results with collect.
Software Design for Python Programmers
The Lazy Evaluation Principle postpones a calculation until its result is required, particularly when the calculation is expensive or time-consuming.
- How it is used
- Improves runtime performance by postponing expensive date-representation conversions until getters or arithmetic operations require them.
- How deep it goes
- Explains deferred conversion, synchronized representations, validity flags, and encapsulated access, without detailing conversion algorithms.
- Examples
- Uses a Date class whose getters validate year-month-day values while arithmetic methods validate Julian day numbers.
- What you can do after
- Apply it by guarding expensive conversions with validity checks and triggering them at the first operation that needs their results.
Read how Software Design for Python Programmers explains lazy evaluation →
Fabulous Adventures in Data Structures and Algorithms
Laziness is an evaluation strategy that defers computation until its result is needed.
- How it is used
- Uses deferred computation to represent large sequences and compose workflows without immediately producing every result.
- How deep it goes
- Explains iterator-based deferral, eager-versus-lazy trade-offs, and Map and Bind, but does not develop evaluation internals.
- Examples
- Demonstrates lazy Cartesian products and Lazy<T> transformations with Map and Bind.
- What you can do after
- Build it from scratch with C# iterators and compose lazy workflows using Map and Bind.
Read how Fabulous Adventures in Data Structures and Algorithms explains lazy evaluation →
Also covered in
- Django in Action
- Practices of the Python Pro
- Learn C++ by Example
- Write Powerful Rust Macros
- F# in Action: A Revised Edition of Get Programming with F#
- Outlier Detection in Python
- Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- listA list is an ordered collection of elements arranged in a sequence.
- eager evaluationEager evaluation is an evaluation strategy in which expressions are computed as they are encountered rather than deferred until their values are needed.
- performancePerformance is a measure of how effectively a person, process, model, or system achieves its objectives, including qualities such as output quality, speed, and resource efficiency.
Related concepts
- eager evaluationcontrasts with · Eager evaluation is an evaluation strategy in which expressions are computed as they are encountered rather than deferred until their values are needed.
- Haskellused by · Haskell is a statically typed, purely functional general-purpose programming language with non-strict, typically lazy evaluation.
- Func<T>includes · Func is a family of .NET generic delegate types representing functions with specified parameter types and a return type.
- functionkind of · A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- functional programmingused by · Functional programming is a programming paradigm that expresses computation through the evaluation and composition of functions, typically favoring immutable data and minimizing mutable state and side effects.
- generatorimplemented by · A generator is a language construct or computation that produces values incrementally on demand, typically suspending and resuming while preserving its state.
Questions about lazy evaluation
What is lazy evaluation?
Lazy evaluation is an evaluation strategy that defers computing an expression until its value is needed, potentially avoiding the computation entirely.
Which Manning books explain lazy evaluation?
Functional Programming in Scala, Second Edition, Fast Python: High performance techniques for large datasets, Functional Programming in C#, Second Edition, Tiny Python Projects: Learn coding and testing with puzzles and games, Functional Programming in JavaScript, Software Engineering for Data Scientists, Systems Programming with Zig, Kotlin in Action, 2E and 8 more.
What should I know before learning lazy evaluation?
Manning books that teach lazy evaluation usually introduce function, list, eager evaluation and performance first.
What is the difference between lazy evaluation and eager evaluation?
Lazy evaluation is an evaluation strategy that defers computing an expression until its value is needed, potentially avoiding the computation entirely. Eager evaluation is an evaluation strategy in which expressions are computed as they are encountered rather than deferred until their values are needed.
What kinds of lazy evaluation are there?
Kinds of lazy evaluation include Func<T>.
What is lazy evaluation a kind of?
Lazy evaluation is a kind of function. A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
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.















