IT lexicon › Programming › Pattern matching

Pattern matching

Programming På svenska → Updated: 2026-07-30

Language feature: destructure + match values against structural patterns in an expression. ML family (OCaml, Haskell) standard since the 1970s. Modern adoption: Rust, Scala, Swift, Java 21+, Python 3.10+ (match statement).

Rust: match opt { Some(x) => x * 2, None => 0 }. Java 21: switch (obj) { case Integer i -> ..., case String s when s.length() > 10 -> ... }. Powerful due to combined destructuring + branching + exhaustiveness check. Distinct from regex (text pattern) or switch-case (value equality). Trade-off: powerful syntax, some learning curve. Modern OOP alternative to Visitor pattern. Algebraic data types (sum types) + pattern matching = "make illegal states unrepresentable" idiom.

← Back to the lexicon