July 2018
Intermediate to advanced
574 pages
14h 7m
English
The following snippet shows how pattern matching can be done on tuples:
iex> {number, representation} = {3.1415, "π"}{3.1415, "π"}iex> number3.1415iex> representation"π"
The process here is the same as we have described in the preceding snippet. By setting the {number, description} pattern on the left-hand side, we're stating that we expect a tuple with two values—again, if that's not the case, a MatchError will be raised. In this case, the match succeeds, and we can see that the variables number and representation are bound to the expected values.
Read now
Unlock full access