I'm in the process of learning Elixir and I was curious why the following occurs:
iex(4)> case {:one, :two} do
...(4)> {:four, :five} ->
...(4)> "This won't match"
...(4)> {:one, x} ->
...(4)> "This will match and bind `x` to `:two`"
...(4)> _ ->
...(4)> "This will match any value"
...(4)> end
"This will match and bind `x` to `:two`"
So if in this 'Pattern Matching' example, why does the empty variable x
automatically bind to the atom :two
and provide a positive match? x
doesn't equal :two
when this case
is first run.
I'm just not grasping what exactly is going on.
Thanks.