Referential transparency means replacing a function call with its result without changing program behavior. The property holds when the function always returns the same output for the same inputs and does not depend on external or mutable shared state. section 6.1.2
When replacement is safe
A pure transformation can be substituted freely: a function that filters and uppercases a collection depends only on its input. Replacing its call with the resulting collection preserves behavior. Replacing a database write, HTTP request, global-counter update, or current-time read does not, because external state can change the result or behavior. section 6.1.2
Prefer referentially transparent functions because they provide:
- Predictability: identical inputs produce identical outputs. section 6.1.2
- Testability: outputs can be asserted without mocking external systems or tracking hidden state. section 6.1.2
- Composability and readability: small, single-purpose functions combine into larger transformations. section 6.1.2








