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 ...
Get From Ruby to Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.