Use of the if and unless Keywords

Learn about the functionalities of the if and unless keywords in Elixir.

We'll cover the following

In Elixir, we write lots of small functions. A combination of guard clauses and pattern matching of parameters replaces most of the control flow seen in other languages.

However, Elixir does have a small set of control-flow constructs. The reason we waited so long to introduce them is that we should try not to use them much. We should drop the occasional cond or case into our code. But before we do, let’s consider more functional alternatives. The benefit will become obvious as we write more code—functions written without explicit control flow tend to be shorter and more focused. They’re easier to read, test, and reuse.

Get hands-on with 1200+ tech skills courses.