# Pure Function A function that (1) always returns the same output for the same input and (2) has no side effects. The building block of functional programming and a useful mental model far beyond it. ## Properties - **Deterministic**: same inputs, same output. No hidden state, no randomness, no dependency on external mutable data - **No side effects**: does not modify external state, write files, send network requests, or mutate arguments - **Referentially transparent**: the function call can be replaced with its return value without changing program behavior ## Why they matter Pure functions are easy to test (no setup), easy to compose (output of one feeds into another), easy to parallelize (no shared state), and easy to reason about (no surprises). ## Beyond code The mental model applies anywhere you want predictable, composable units: - **AI skills as pure functions**: a well-designed skill takes clear inputs (context, arguments, dependencies) and produces consistent outputs (same structure given same context). It declares what it reads and writes. This makes skills composable, testable, and safe to chain. See [[Software Design Patterns for AI Skills and Agents]] - **Data pipelines**: each transformation stage is a pure function; the pipeline is their composition - **Build systems**: deterministic builds from the same inputs In practice, most useful functions have *some* side effects (reading files, calling APIs). The discipline is to minimize and isolate them, keeping the core logic pure. ## References - ## Related - [[SOLID Principles]] - [[AI Skill Composability]] - [[AI Skill Best Practices]] - [[Idempotency]] - [[Composition over Inheritance]]