On this page
  1. Functional Programming
  2. Contents
  3. Pure Functions & Referential Transparency
  4. Immutability & Pipeline Composition
  5. Functional Core, Imperative Shell

Functional Programming

Prev: Object-Oriented Programming | Up: paradigms | Next: Declarative & Event-Driven Programming
Rel: Functions & Recursion, Type Systems, Python Iterators & Generators
Ref: Wikipedia — Functional Programming
Tags: #public #prog #programming #paradigms #functional


Contents


Pure Functions & Referential Transparency

A pure function:

  1. Always returns the exact same output for the same inputs (deterministic).
  2. Produces no side effects (no mutating global state, no I/O, no clock/randomness reads).

Because of referential transparency, any pure call can be safely memoized, reordered, parallelized, or tested in isolation without mocks.


Immutability & Pipeline Composition

Instead of mutating a collection in place, functional code composes small transformations (map, filter, reduce / fold) over immutable values:

orders
  |> filter(o => o.status == "paid")
  |> map(o => o.total_cents)
  |> reduce(0, (acc, x) => acc + x)

Functional Core, Imperative Shell

Real programs must perform I/O (databases, network, files). Keep business logic in pure functions (functional core) and push I/O, retries, and state mutation to thin outer boundaries (imperative shell).

Linked from

Related notes