June 2022
Intermediate to advanced
130 pages
2h 45m
English
Elixir is immutable, meaning our algorithms won’t iterate the way you might see them do in a procedural language like C or an object-oriented language like Python. Instead of iteration, functional languages use pattern matching and functions.
Recursion picks off the head from a list, deals with it directly, and then makes a recursive call to deal with the rest. Here’s an example of using a list with recursion over the tail.
| | def total([]), do: 0 |
| | def total([head|tail]), do: head + total(tail) |
If you’ve not seen code like this before, take a little time to understand what’s going on. The first clause is easy to understand. The total of an empty list is zero. The second feels a bit like ...
Read now
Unlock full access