June 2022
Intermediate to advanced
130 pages
2h 45m
English
For the most part, Elixir doesn’t have as many data structures as typical procedural or object-oriented languages. Instead, programmers will use other features such as functions or pattern matching. We’ll look at three now: if/unless, case, and cond. We’ll save with for later.
You’ve already seen one way to do comparisons in Elixir, and it’s often a good way. In the Color module, we used pattern matching within our function head to compare values. The performance of this kind of comparison is very good.
Another way to do such comparisons is with the if statement. Go to your IEx session. Let’s assign a variable to compare against, like this:
| | iex(16)> x = 10 |
| | 10 |
Now, let’s use
Read now
Unlock full access