I defined the module Fooas follows:
defmodule Foo do
def hello(x = %{name: name}) do
IO.inspect [x, name]
end
end
If I run Foo.hello(%{name: "Alice"}), I get the following result:
[%{name: "Alice"}, "Alice"]
Then I found out that I can rewrite a module Foowithout changing its functionality as follows:
defmodule Foo do
def hello(%{name: name} = x) do
IO.inspect [x, name]
end
end
Why is this possible? What is an equal sign in a function parameter? Is this a regular match operator?
In my understanding, the operator =corresponds to the value on the right side relative to the picture on the left side.
[change]
After reading Justin's answer, I sent the answer myself. But I still need help.
I want to know if the operator =performs functions differently in the head and why.
And I want to find official documentation, if available.