iex> a = %{1 => [2,3]}
%{1 => [2, 3]}
iex> %{k => [v1, v2]} = a
But its not possible to match on variable keys. The error you will get with the above is:
** (CompileError) iex:2: cannot use variable k as map key inside a pattern. Map keys in patterns can only be literals (such as atoms, strings, tuples, etc.) or an existing variable matched with the pin operator (such as ^some_var)
(stdlib 3.9.1) lists.erl:1263: :lists.foldl/3
You can match on the value and shape of a key such as:
iex> %{1 => [v1, v2]} = a
%{1 => [2, 3]}
The reasoning is that if the key is a variable, Elixir/Erlang would have to scan the entire map to see if any entries match and that is rarely what is intended. Additionally, such a variable match could match more than one map entry and the semantics of matching don’t implement a multiple match.