Guardians Of The Elixir Functions — Tentamen Software Testing Blog

Image by Capri23auto from Pixabay

TL;DR

In the previous post, we introduced function overloading in Elixir, which is basically applied pattern matching to function input arguments. As pattern matching could not include logical operators, guards are mechanisms that extend function overloading with logical operators. This post is part of the functional language series, and it is based on the remarkable book Elixir In Action by Sasa Juric.

Elixir Function Guards

Remember

  • You reach for guards when you need an in-function argument pattern matching logical expressions.
  • Elixir is not the type-safe language; you could easily end up comparing an atom with a number without any warning.
  • In guards, you can use a limited set of functions.
  • Elixir function overloading and guards help you to avoid complex, long and nested if then else statements

Founder of Tentamen, software testing agency.