The following snippet is from “Programming Elixir 1.6”
defmodule Users do
dave = %{ name: "Dave", state: "TX", likes: "programming" }
case dave do
%{state: some_state} = person ->
IO.puts "#{person1.name} lives in #{some_state}"
_ ->
IO.puts "No matches"
end
end
I understand how the pattern matching works… My question is about the person variable… I played with the snippet - and understand that it binds to the variable dave - and yes - the match is successful when the key state matches…
However the person -> ... syntax is a bit baffling - could someone point me to the documentation? I think I understand what is happening - just never found the documentation for the same…
It’s precisely because = is right associative that this works. The right most = establishes a match context on the left, and a value on the right. Then any further = to the left work precisely as they do in any other match context.