TL;DR
In the previous post, we explain three ways how to run the Elixir script. Today we present four ways how to do control flow in Elixir. This post is part of the functional language series, and it is based on the remarkable book Elixir In Action by Sasa Juric.
Pattern Matching
Pattern matching is a new way of solving problems in functional languages. I first met with pattern matching in Elixir. You probably met with regular expression matching, where the pattern is a String. In Elixir, a pattern is not only a String.
Multiclause Functions
In Java, you can overload a function with the same name and different input parameters. This is similar in Elixir, but with the addition of pattern matching, that gives you much more flexibility.
Conditional Expressions
Here we have traditional if then else. But Elixir also has with
, case
and cond
statements. More flexibility for programmers.
Loops
There is no traditional While, For, and Loop statement. But using functional recursion, you can solve all looping problems, with no more than OO complexity.
We will first start with pattern matching in the following blog post.
Comments are closed.