Elixir Fundamentals interview question · Most asked
How does pattern matching work in Elixir?
Summary
= is the match operator: the left side is a pattern matched against the right side, binding variables; a mismatch raises MatchError. Patterns are used in function heads, case, with and receive; ^ pins an existing value.
Longer Answer
Tagged tuples like {:ok, value} and {:error, reason} rely on pattern matching.
Key Points
- = matches, not assigns.
- Destructure tuples, lists, maps.
- ^ pins; _ ignores.
Deep dive: Elixir Fundamentals: Pattern Matching