TL;DR
In the previous post, we explained how to make pattern matching on Elixir Lists. Today we move on pattern matching Elixir Maps. This post is part of the functional language series, and it is based on the remarkable book Elixir In Action by Sasa Juric.
Map Pattern Matching
In the screenshot above, we first recapped two ways how we define Elixir Map.
Then we did a pattern match, similar to Tuple Pattern Matching. It is important to state that on the pattern side (left side), we can only declare what we are interested in, as long that the Map key exists. For example, we can only pattern match type. This is called the partial matching rule.
And for the end, we have a Pattern Match error.
Comments are closed.