liveBook · Manning

Pattern matching

Pattern matching is the process of comparing data or values with specified or learned patterns to identify correspondence, conformity, or a matching case.

How 12 Manning books explain it

Functional Programming in Scala, Second Edition

Pattern matching is a language feature that selects a case by comparing a target expression with structural patterns and evaluates the corresponding result.

How it is used
Uses pattern matching to define pure operations over immutable functional data structures.
How deep it goes
Explains case order, nested destructuring, bindings, wildcards, guards, and exhaustiveness through recursive list functions.
Examples
Works through `sum`, `product`, nested `Cons` matching, `tail`, `dropWhile`, and pairwise list operations.
What you can do after
Apply it via Scala match expressions to destructure lists and write recursive pure functions.

Read how Functional Programming in Scala, Second Edition explains pattern matching →

Natural Language Processing in Action, Second Edition

A pattern-matching algorithm selects behavior or responses by comparing an input with predefined textual patterns.

How it is used
Routes rule-based chatbot greetings and extracts recognizable information from natural-language input.
How deep it goes
Works through Python greeting matches and captured groups, then explains where character matching falls short of meaning.
Examples
Uses greeting regex matches, captured names, and Python sentence-splitting outputs, including a difficult quotation.
What you can do after
Build it from scratch with Python `re` for greeting detection or sentence splitting, then inspect matches and boundary failures.

Read how Natural Language Processing in Action, Second Edition explains pattern matching →

Elixir in Action, Third Edition

Pattern matching is a language mechanism that compares a value with a pattern and succeeds when their structure and contents conform, binding variables in the pattern.

How it is used
Uses structural data checks to decompose values, select function clauses, validate results, and express recursive iteration.
How deep it goes
Explains tuple, list, binary, nested, chained, constant, function-argument, and with-pattern behavior, while deferring the complete pattern reference.
Examples
Demonstrates people tuples, calendar values, file reads, binary commands, geometry dispatch, user extraction, and recursive list processing.
What you can do after
Apply it to destructure data, dispatch functions by input shape, compose tagged operations, and implement recursive list processing.

Read how Elixir in Action, Third Edition explains pattern matching →

F# in Action: A Revised Edition of Get Programming with F#

Pattern matching is a language feature that selects behavior by testing a value against structural or value patterns and binding matched components.

How it is used
Provides F#’s primary mechanism for conditional logic and consuming discriminated unions.
How deep it goes
Explains syntax, ordering, compiler warnings, tuples, records, lists, and union cases; defers other pattern forms to documentation.
Examples
Demonstrates console modifiers, loan decisions, customer records, loan-request lists, contact methods, and optional numbers.
What you can do after
Apply it via F# match expressions to branch on data shapes and handle modeled cases explicitly.

Read how F# in Action: A Revised Edition of Get Programming with F# explains pattern matching →

The Art of Code

Pattern matching is a language mechanism that tests an object's structure and can extract its components when the structure matches.

How it is used
Routes behavior according to data shape or category, especially in data-oriented branching.
How deep it goes
Defines predicates, targets, and bindings, then demonstrates guarded record patterns in enhanced switch expressions.
Examples
Uses PhysicalProfile and BMI categories, plus a Number-to-int refactoring exercise.
What you can do after
Apply it via Java 21 switch or instanceof patterns to make data-driven routing clearer.

Read how The Art of Code explains pattern matching →

Learn Haskell by Example

Pattern matching is a language mechanism that selects computation branches by comparing values against structural patterns.

How it is used
Structures recursive list functions and command-line argument parsing around the possible shapes of input.
How deep it goes
Explains list constructors, recursive equations, exhaustiveness, single-element and wildcard patterns; defers error values to Maybe.
Examples
Demonstrates listLength, indexOf, a Caesar cipher, and parsing a single filename argument.
What you can do after
Build recursive Haskell functions that deconstruct lists, cover structural cases, and discard unused fallback input.

Read how Learn Haskell by Example explains pattern matching →

Idiomatic Rust

Pattern matching is a language feature that selects behavior by testing a value against structurally defined patterns and optionally binding parts of the value.

How it is used
Controls runtime code flow by matching values, destructuring data, and handling optional cases.
How deep it goes
Explains exhaustive matches, bindings, guards, and value and structure patterns through Rust examples and compiler diagnostics.
Examples
Uses Option cases, integer ranges, tuple destructuring, enum variants, struct fields, and guarded matches.
What you can do after
Apply exhaustive matches to unwrap Option values, destructure data, select behavior, and handle cases clearly.

Read how Idiomatic Rust explains pattern matching →

DuckDB in Action

Pattern matching is the comparison of strings against specified wildcard or regular-expression patterns.

How it is used
Filters relational data by wildcard, filename-like, or regular-expression conditions.
How deep it goes
Defines four matching approaches and demonstrates one regular-expression filter, but does not develop regex syntax.
Examples
Uses a country population table to locate Eastern Europe records and intersect them with a population threshold.
What you can do after
Apply it via DuckDB to filter strings and combine matching records with other relational results.

Read how DuckDB in Action explains pattern matching →

Learn Rust in a Month of Lunches

Pattern matching is the process of comparing a value against structural patterns and handling the matching case.

How it is used
Uses structural cases to replace crowded conditional chains and safely handle alternatives such as Option values.
How deep it goes
Explains arm syntax, exhaustive coverage, wildcards, expressions, tuples, guards, ordering, and compatible result types.
Examples
Uses numbers, weather tuples, color tuples, marital status, and Some or None values as matching examples.
What you can do after
Apply it via Rust match expressions to branch on values, extract nested data, return results, and handle missing cases.

Read how Learn Rust in a Month of Lunches explains pattern matching →

Functional Design and Architecture: Examples in Haskell

Pattern matching is a language mechanism that selects behavior by matching a value against structural patterns and binding its components.

How it is used
Uses structural cases to calculate results, propagate optional failures, and interpret free-monadic domain scripts.
How deep it goes
Explains extraction, typed rejection, nested Maybe cases, and recursive Free interpretation, but defers formal matching semantics.
Examples
Demonstrates Shape area calculation, nested Maybe lookups, do notation, and a SandwichRecipe free interpreter.
What you can do after
Apply it via Haskell definitions to branch on data constructors, extract fields, and process recursive interpreter structures.

Read how Functional Design and Architecture: Examples in Haskell explains pattern matching →

The Well-Grounded Rubyist, Fourth Edition

Pattern matching is a technique for selecting behavior by testing the structural shape and contents of a value against declarative patterns.

How it is used
Uses regular expressions for text processing and case...in for branching on object structure.
How deep it goes
Explains regular-expression applications, structural captures, type constraints, guards, and grep's reliance on ===.
Examples
Demonstrates array-shape descriptions, grade calculation, regular-expression selection, class selection, and range selection.
What you can do after
Apply pattern matching through Ruby regular expressions, case...in statements, and Enumerable#grep.

Read how The Well-Grounded Rubyist, Fourth Edition explains pattern matching →

100 C++ Mistakes and How to Avoid Them

Pattern matching is the process of determining whether structured data conforms to a specified pattern.

How it is used
Uses pattern matching to validate and split textual input such as email addresses.
How deep it goes
Contrasts handwritten checks with regular expressions and briefly connects matching to state machines, stopping short of parser construction.
Examples
Demonstrates email validation with separator checks and a regular expression.
What you can do after
Apply it via std::regex to replace fragile handwritten checks for structured textual input.

Read how 100 C++ Mistakes and How to Avoid Them explains pattern matching →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.