Level Up Your Functions
Pattern matching takes function overloading to a new level. The most basic type of function overloading lets you define the same function name with a different number of arguments, but Elixir supports more than this.
We’ll go over function overloading, how it’s implemented, and how it can be used to create seamless recursive functions. But first, we need to cover a helpful addition to pattern matching called guards.
Guards
While pattern matching is really powerful, it can’t do certain things. Pattern matching operates on the structure of a value, but sometimes we want to go beyond that. For example, we may want to know whether a number is within a certain range, whether a value is in a predefined list, or what the type ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access