June 2022
Intermediate to advanced
130 pages
2h 45m
English
Matching tuples is easy in Elixir because tuples have fixed sizes. For example, our points all have two elements. Lists are a bit trickier to match because they can be any length. Let’s match a few lists.
| | ie> list |
| | [1, 2, 3] |
| | ie> [head|tail] = [1, 2, 3] |
| | [1, 2, 3] |
| | iex> head |
| | 1 |
| | iex> tail |
| | [2, 3] |
| | iex> [] = [1, 2, 3] |
| | ** (MatchError) no match of right hand side value: [1, 2, 3] |
| | (stdlib) erl_eval.erl:453: :erl_eval.expr/5 |
| | (iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5 |
| | (iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3 |
| | (iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3 |
| | (iex) lib/iex/evaluator.ex:103: IEx.Evaluator.loop/1 |
| | (iex) lib/iex/evaluator.ex:27: IEx.Evaluator.init/4 |
| | iex> ... |
Read now
Unlock full access