Programs are built from pure functions — predictable mathematical mappings of input to output. No hidden state, no surprises.
← Back to FoundationsIf procedural says "do this then that" and OOP says "ask this object to do that," functional says "this is a transformation of input into output."
map, filter, reduce).No side effects. Easy to test, cache, parallelize, and reason about.
Once created, values don't change. Eliminates whole classes of bugs.
Build big behaviors by chaining small functions: f(g(x)).
Say what you want, not how to compute it. map over for.
An expression can be replaced with its value without changing program meaning.
// JavaScript — sum of squares of even numbers const result = [1, 2, 3, 4, 5, 6] .filter(n => n % 2 === 0) // [2, 4, 6] .map(n => n * n) // [4, 16, 36] .reduce((a, b) => a + b, 0); // 56
Same logic in procedural style would need a loop, a temp variable, and three if/accumulator steps.
const add = a => b => a + b; // curried const add5 = add(5); // partial application add5(3); // 8
Building specialized functions from general ones, by fixing some arguments up front.
-- Haskell: factorial
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial (n - 1)
FP languages often optimize tail recursion into loops, so you don't blow the stack.
-- Haskell: define an algebraic type, match on its shape data Shape = Circle Double | Square Double | Rectangle Double Double area :: Shape -> Double area (Circle r) = pi * r * r area (Square s) = s * s area (Rectangle w h) = w * h
Algebraic data types + pattern matching = a uniquely powerful way to model data.
A monad is a wrapper around a value with a standard way to chain operations. Examples:
Maybe / Option — value or nothing (no nulls).Either / Result — success or error (no exceptions).Promise / Future — async value.IO — controlled side effects.If you've used .then() on JavaScript Promises, you've used a monad — without the scary name.
Don't compute a value until it's actually needed. Enables infinite data structures (like an infinite list of primes) and big performance wins.
| Language | Style | Notes |
|---|---|---|
| Lisp / Scheme / Clojure | Pure-ish, dynamic | Code is data; macros are unmatched. |
| Haskell | Pure, lazy, typed | The textbook FP language. Pure functions enforced by the type system. |
| F# | Pragmatic, .NET | OCaml-derived; runs on .NET; great interop with C#. |
| OCaml | Pragmatic | Powers Jane Street, parts of Facebook, Coq. |
| Erlang / Elixir | Concurrent | Massive concurrency on the BEAM VM. Powers WhatsApp, Discord. |
| Scala | Hybrid | OOP + FP on the JVM. |
| JavaScript / Python | Multi-paradigm | Embrace many FP idioms — map, filter, lambdas. |
ETL, analytics, transforming streams of records.
Erlang/Elixir for chat, telecom, real-time messaging.
Trading rules, pricing models — math maps cleanly to functions.
OCaml, Haskell shine when transforming trees of code.
React + Redux is FP-flavored — pure reducers, immutable state.
Immutability + message passing make consensus easier.