I was going through elixirschool.com and I am stuck to understand what the author means by specifically this kind of pattern matching. The other kinds I get it, but this one doesn’t make sense.
Functions and Pattern Matching
Behind the scenes, functions are pattern-matching the arguments that they’re called with.
Say we needed a function to accept a map but we’re only interested in using a particular key. We can pattern-match the argument on the presence of that key like this:
defmodule Greeter1 do
def hello(%{name: person_name}) do
IO.puts "Hello, " <> person_name
end
end
This was the output from iex. A bunch of numbers?
{:module, Greeter1,
<<70, 79, 82, 49, 0, 0, 4, 52, 66, 69, 65, 77, 65, 116, 85,
56, 0, 0, 0, 133, 0, 0, 0, 14, 15, 69, 108, 105, 120,
105, 114, 46, 71, 114, 101, 101, 116, 101, 114, 50, 8,
95, 95, 105, 110, 102, 111, ...>>, {:hello, 1}}
So can anyone elaborate what’s happening here?