Everything You Always Wanted to Know About Pattern Matching
summary
Explains how Scala pattern matching works under the hood: extractor objects use unapply/unapplySeq and may return a boolean, an Option[T], an Option[(T1,T2)], or any object with isEmpty/get and _1/_2, which the compiler treats accordingly; the match phase inserts instance checks and builds a decision tree and can be inspected with -Xprint:patmat. Notes performance (allocations, name‑based extractors in Scala 2.11) and surprising facts: case classes can exceed the 22-field limit because pattern matching accesses fields directly; regex and string‑context extractors and @switch are intent annotations.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 2:48Constant Pattern
- 4:23Common Mistakes
- 12:33Metric
- 13:08Minutes Hours
- 13:33Pattern Matching
- 15:18Plus It Takes
- 16:53Apply
- 24:03Double colon
- 25:28Plus colon
- 27:53Pattern match
- 29:48Case classes
- 30:38Companion objects
- 32:43Using fields directly
- 34:23Using variables
- 39:48Lookups
- 42:33Summary








