Pure function
A pure function is a function whose result depends only on its explicit inputs and whose evaluation has no externally observable side effects.
The Joy of JavaScript
- How it is used
- Uses pure functions to express predictable business logic as composable transformations while separating necessary application effects.
- How deep it goes
- Defines purity and referential transparency, then works through dependency exposure, decomposition, composition, and practical effect boundaries.
- Examples
- Uses array filtering and reduction, transaction hashing, wallet-balance calculation, and file word counting as concrete cases.
- What you can do after
- Practice/perform refactoring that exposes hidden dependencies, composes pure calculations, and isolates effectful work.
Functional Programming in JavaScript
- How it is used
- Uses pure functions to reduce shared-state complexity in functional JavaScript programs.
- How deep it goes
- Explains purity through stateful counter and student-display refactorings, then connects it to decomposition and composition.
- Examples
- Contrasts counter increment, array squaring, average calculation, and student-display code that reads data and updates the DOM.
- What you can do after
- Evaluate/understand whether JavaScript logic relies on external state and refactor it into smaller composable functions.
Read how Functional Programming in JavaScript explains pure function →
Functional Programming in C#, Second Edition
A pure function's result depends only on its inputs and it has no observable side effects.
- How it is used
- Uses purity to make functional application logic more predictable, testable, and suitable for concurrent execution.
- How deep it goes
- Defines both requirements and side effects, then works through refactoring, testing, and parallel execution without developing algebraic proofs.
- Examples
- Uses a parallel list formatter, a date validator, and an account debit operation.
- What you can do after
- Apply purity by passing in values, returning new state, and isolating unavoidable I/O.
Read how Functional Programming in C#, Second Edition explains pure function →
Functional Programming in Scala, Second Edition
A pure function is a function whose result depends only on its arguments and whose evaluation has no observable side effects.
- How it is used
- Establishes functional programming’s core discipline and guides refactoring effects into explicit outer layers.
- How deep it goes
- Defines purity through referential transparency, demonstrates substitution failure, and qualifies the rule with locally scoped mutation.
- Examples
- Contrasts StringBuilder.append with string reversal, then refactors a player contest and implements local-mutation quicksort.
- What you can do after
- Apply it by extracting pure computations from effectful procedures and isolating I/O at program boundaries.
Read how Functional Programming in Scala, Second Edition explains pure function →
The Art of Code
A pure function is a function that produces the same result for the same inputs without observable side effects or dependence on external mutable state.
- How it is used
- Uses purity to make data transformations predictable, composable, and readable.
- How deep it goes
- Defines purity and referential transparency, then examines hidden mutation and practical tradeoffs in pipelines.
- Examples
- Uses a Java title-sorting stream, a mutable book captured by a lambda, and a Haskell title transformation separated from printing.
- What you can do after
- Evaluate and understand whether transformations hide state or side effects, and choose a clearer functional or imperative approach.
Modern C, Third Edition
A pure function is a function whose interactions with the rest of a program occur only through its interface and whose behavior has no other observable effects.
- How it is used
- Uses pure functions to modularize small tasks with predictable interfaces and optimization opportunities.
- How deep it goes
- Defines purity through effects and state dependency, then examines verification and implicit floating-point state.
- Examples
- Illustrates purity with rational-number constructors and contrasts it with a pointer-based swap.
- What you can do after
- Evaluate functions for purity by checking their dependencies and observable effects.
Build a Frontend Web Framework (From Scratch)
A function that produces the same output for the same inputs and has no observable side effects.
- How it is used
- Uses pure functions to generate component views from application state and to calculate new state in reducers.
- How deep it goes
- Defines determinism and side effects, then demonstrates view composition and immutable reducer updates; component-held state is treated separately.
- Examples
- Shows a to-do list view, a composed application view, and an add-to-do reducer.
- What you can do after
- Build it from scratch as JavaScript view functions and reducers that return results without changing their inputs.
Read how Build a Frontend Web Framework (From Scratch) explains pure function →
Data-Oriented Programming in Java
A pure function is a computation that produces the same output for the same inputs without observable side effects or dependence on mutable external state.
- How it is used
- Separates data acquisition from domain calculations so business rules become deterministic input-to-output mappings.
- How deep it goes
- Defines purity, contrasts impure dependencies, derives Java conventions, and models relationships as returned functions without language enforcement.
- Examples
- Uses increment, USD addition with logging, due-date calculation, grace-period adjustment, invoice past-due rules, and input-output tests.
- What you can do after
- Apply it by extracting environmental reads and service calls from business rules, then testing explicit inputs against expected outputs.
Read how Data-Oriented Programming in Java explains pure function →
F# in Action: A Revised Edition of Get Programming with F#
Functional purity is the property of functions having deterministic outputs for given inputs and no observable side effects.
- How it is used
- Uses pure functions to make state transitions explicit and unit tests repeatable.
- How deep it goes
- Defines purity and side effects, then works through separating customer text from printing; notes that F# does not guarantee purity.
- Examples
- Contrasts mutable and immutable gas tracking, then separates customer-description text from console printing.
- What you can do after
- Build it from scratch by passing state as arguments, returning updated values, and testing those outputs directly.
Read how F# in Action: A Revised Edition of Get Programming with F# explains pure function →
Functional Design and Architecture: Examples in Haskell
A pure algorithm is an algorithm whose result is determined by its inputs and which produces no observable side effects.
- How it is used
- Uses purity to make functional computations predictable and easier to test and compose.
- How deep it goes
- Defines purity and determinism, then illustrates composition, type-based effect separation, and testing without claiming tests prove correctness.
- Examples
- Illustrates composition with a maximum-and-average calculation and testing with a square function.
- What you can do after
- Apply it via hspec and QuickCheck to test concrete cases and generated properties of pure functions.
Read how Functional Design and Architecture: Examples in Haskell explains pure function →
The Well-Grounded Rubyist, Fourth Edition
A pure function is a computation that produces its result from its inputs without observable side effects or dependence on mutable external state.
- How it is used
- Uses pure functions to make Ruby computations predictable while contrasting functional style with stateful object behavior.
- How deep it goes
- Defines purity and referential transparency, then works through mutating and nonmutating Ruby methods; does not pursue the underlying mathematics deeply.
- Examples
- Contrasts array summation with `shift` and `reduce`, shows arithmetic and `map`, and refactors a grading calculation.
- What you can do after
- Diagnose/debug with it by checking whether a Ruby method’s result depends only on inputs and whether it changes observable state.
Read how The Well-Grounded Rubyist, Fourth Edition explains pure function →
Modern C
A mathematical function is a C library function that computes a numerical or mathematical result.
- How it is used
- Uses interface-only functions to improve readability, modularity, and optimization in C code.
- How deep it goes
- Defines purity, lists disqualifying effects, and explains optimization consequences while deferring local static variables to later treatment.
- Examples
- Demonstrates rational-number constructors, normalization, scaling, multiplication, and addition as value-returning operations.
- What you can do after
- Evaluate whether a C function is pure and recognize when its result permits movement or parallel execution.
React Quickly, Second Edition
A pure function is a function whose result depends only on its arguments and that has no observable side effects.
- How it is used
- Uses pure utilities to simplify React functional components and convert class methods that need no component-local information.
- How deep it goes
- Defines argument dependence and side-effect freedom, then works through React conversion trade-offs without examining implementation internals.
- Examples
- Demonstrates image-source generation in a gallery and compares external utilities with methods reading component properties.
- What you can do after
- Apply it by extracting React utilities, passing required properties explicitly, and identifying when a local function is simpler.
Read how React Quickly, Second Edition explains pure function →
Learn Haskell by Example
A pure function is a function whose result depends only on its inputs and that produces no observable side effects.
- How it is used
- Separates deterministic transformations from operating-system interaction in command-line tools.
- How deep it goes
- Explains the pure-versus-IO boundary through program tasks and testing rationale, without detailing compilation behavior.
- Examples
- Uses an uppercase line reader and a file line-numbering tool with parsing, filtering, formatting, and printing tasks.
- What you can do after
- Apply it via IO actions by keeping input, file access, and output impure while transforming data with pure functions.
Write Powerful Rust Macros
A pure function is a function with no observable side effects whose result depends only on its input parameters.
- How it is used
- Uses pure functions to isolate transformations and business logic, improving reasoning and testing while containing interactions with external systems.
- How deep it goes
- Defines determinism and side effects, contrasts database access, and applies the distinction to testing and code organization.
- Examples
- Demonstrates fixed-threshold summation and contrasts it with summation governed by a database query.
- What you can do after
- Apply pure functions to write deterministic business logic that can be tested without mocking external dependencies.
Read how Write Powerful Rust Macros explains pure function →
Deep Learning with R, Third Edition
A pure function produces results solely from its explicit inputs and has no externally observable side effects.
- How it is used
- Uses explicit inputs instead of hidden global state to make computations repeatable and compatible with stateless execution.
- How deep it goes
- Explains repeatability through random keys and seed management, while stopping short of a general side-effect taxonomy.
- Examples
- Demonstrates R noise generation with explicit seeds and JAX normal sampling with repeated and split PRNG keys.
- What you can do after
- Apply it via explicit seeds or JAX PRNG keys to reproduce random computations and manage new random states deterministically.
Read how Deep Learning with R, Third Edition explains pure function →
React in Depth
A pure function produces the same return value for the same inputs and has no dependence on external state, randomness, or side effects.
- How it is used
- Keeps React renders and lifecycle-related functions safe to rerun during scheduling, Strict Mode checks, and future component reactivation.
- How deep it goes
- Defines input dependence and outside effects, then demonstrates failures under Strict Mode without developing a general purity formalism.
- Examples
- Uses an external counter, repeated initializers, effect-driven state updates, cleanup logs, and memoized addition.
- What you can do after
- Diagnose rerun bugs and choose memoization only when a function’s output depends solely on its inputs.
Acing the Frontend Interview
A pure function is a function that returns the same output for the same input without producing side effects or depending on external mutable state.
- How it is used
- Supports interview preparation by evaluating predictable, modular JavaScript and TypeScript programming.
- How deep it goes
- Defines purity, contrasts code examples, explains practical benefits, and connects it to map without exploring runtime internals.
- Examples
- Uses counter mutation, addition, and array doubling with map to distinguish impure functions from pure transformations.
- What you can do after
- Apply it via JavaScript functions and map transformations, then explain their effects on predictability, testing, and maintenance.
Read how Acing the Frontend Interview explains pure function →
High Performance Unity Game Development
A function whose result depends only on its inputs and that produces no externally observable side effects.
- How it is used
- Keeps core gameplay logic independent of Unity-facing objects and accessible for direct testing.
- How deep it goes
- Defines input-only dependencies and deterministic results, including seeded pseudo-randomness, without detailing implementation code.
- Examples
- Tests static functions with directly created GameData and Balance, and uses a seed for repeatable pseudo-random results.
- What you can do after
- Apply static logic functions to game data and verify results without a Unity scene or Game singleton.
Read how High Performance Unity Game Development explains pure function →
Fabulous Adventures in Data Structures and Algorithms
A pure function is a function whose result depends only on its input values and that has no observable interaction with global state.
- How it is used
- Uses purity to justify memoization and eliminate repeated computation in immutable data structures and algorithms.
- How deep it goes
- Defines purity, demonstrates a generic memoizer, and measures cache behavior without detailing a formal effect system.
- Examples
- Uses a C# memoizer, immutable quadtrees, HashLife's Step method, and memoized term-processing operations.
- What you can do after
- Apply it via memoization by identifying repeatable inputs, caching results, and monitoring or clearing cache growth.
Read how Fabulous Adventures in Data Structures and Algorithms explains pure function →
Clojure: The Essential Reference
A pure function produces the same result for the same arguments and has no observable side effects.
- How it is used
- Guides function design toward predictable results and controlled side effects, especially when composing or memoizing functions.
- How deep it goes
- Defines repeatable results and absent observable effects, then explains referential transparency without descending into implementation internals.
- Examples
- Uses memoized Levenshtein distance and contrasts predictable pure output with repeatedly-generated random values and side-effecting workers.
- What you can do after
- Apply memoize safely when function results depend only on arguments and recognize when repeated calls require fresh effects.
Read how Clojure: The Essential Reference explains pure function →
100 Java Mistakes and How to Avoid Them
A stateless function computes each result without depending on mutable state or other invocations of the function.
- How it is used
- Enforces stateless functions in Stream API operations, especially utilities that must remain safe when callers request parallel execution.
- How deep it goes
- Explains state retention, encounter-order assumptions, and parallel failure, but stops short of implementing a general pairwise operation.
- Examples
- Uses a pairMap utility that combines adjacent strings and a stateful Function storing the previous element.
- What you can do after
- Diagnose stateful stream operations, test utilities with parallel(), and choose StreamEx or a non-Stream solution when appropriate.
Read how 100 Java Mistakes and How to Avoid Them explains pure function →
Kotlin in Action, 2E
- How it is used
- Uses pure functions to support Kotlin’s functional style alongside object-oriented programming.
- How deep it goes
- Defines deterministic results and absence of side effects, then connects purity to concurrency, testing, and reasoning.
- Examples
- Shows a collection pipeline and contrasts concise lambda syntax with a button handler that produces observable output.
- What you can do after
- Evaluate/understand whether functions are repeatable, isolated, and free from observable interaction with surrounding state.
Also covered in
- Deep Learning with JAX
- 100 C++ Mistakes and How to Avoid Them
- Idiomatic Rust
- Grokking Simplicity
- Elixir in Action, Third Edition
- Build an AI Agent (From Scratch)
- Type-Driven Development with Idris
- Advanced Algorithms and Data Structures
- Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu
- Simple Object-Oriented Design: Create clean, maintainable applications
- Data Pipelines with Apache Airflow, Second Edition
- Go by Example
What to know first
- side effectA side effect is an observable change or interaction caused by a computation beyond producing its direct result, such as modifying state or interacting with the external environment.
- 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.
- functional programmingFunctional 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.
- stateState is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
Related concepts
- 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.
- side effectcontrasts with · A side effect is an observable change or interaction caused by a computation beyond producing its direct result, such as modifying state or interacting with the external environment.
- impure functioncontrasts with · An impure function is a function whose result depends on external state or whose evaluation produces observable effects beyond its returned value.
- shrinkincludes · shrink is the QuickCheck type-class method that produces smaller candidate values to simplify a failing test case.
- unit testcontrasts with · A unit test is an automated test that checks whether a relatively small unit of software behaves as expected, typically in isolation from external dependencies.
- 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.
Questions about pure function
What is pure function?
A pure function is a function whose result depends only on its explicit inputs and whose evaluation has no externally observable side effects.
Which Manning books explain pure function?
The Joy of JavaScript, Functional Programming in JavaScript, Functional Programming in C#, Second Edition, Functional Programming in Scala, Second Edition, The Art of Code, Modern C, Third Edition, Build a Frontend Web Framework (From Scratch), Data-Oriented Programming in Java and 15 more.
What should I know before learning pure function?
Manning books that teach pure function usually introduce side effect, function, functional programming and state first.
What is the difference between pure function and side effect?
A pure function is a function whose result depends only on its explicit inputs and whose evaluation has no externally observable side effects. A side effect is an observable change or interaction caused by a computation beyond producing its direct result, such as modifying state or interacting with the external environment.
What kinds of pure function are there?
Kinds of pure function include shrink.
What is pure function a kind of?
Pure function 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.






















