December 2022
Intermediate to advanced
528 pages
15h 41m
English
Most functional programming languages—as well as many of the hybrid languages that aspire to support functional programming—define a form of pattern matching. Pattern matching has many uses, from a simple switch-like construct to runtime type checking and casting, but it is most effective when applied to algebraic data types, which combine alternatives and aggregation.
As a starting point, you can think of pattern matching as a form of functional switch. For instance, the earlier example using if-then-else
Scala
val verbosity = if arg == "-v" then 1 else if arg == "-vv" then 2 else 0
could be rewritten to use pattern matching instead:
Read now
Unlock full access