How to do pattern matching on map keys in function heads in elixir : <p>I can't seem to find a way to pattern match on a map's key in a function head. Is there a way to do this? What I'm trying to do is run different code depending on whether a certain key already exists in a map or not (and also wanted to avoid if/else and the like)</p>

<p>This is what my code looks like</p>

<pre class="lang-ex prettyprint-override"><code>def my_func(key, %{key =&gt; _} = map), do: ...
</code></pre>

<p>which gives me this error</p>

<blockquote>
  <p>** (CompileError) illegal use of variable key inside map key match, maps can only match on existing variable by using ^key</p>
</blockquote>

<p>Of course I also tried it using the <code>^</code></p>

<pre><code>def my_func(key, %{^key =&gt; _} = map), do: ...
</code></pre>

<p>which then gives</p>

<blockquote>
  <p>** (CompileError) unbound variable ^key</p>
</blockquote>

<p>I'm using elixir 1.3.1/erlang 19.0 x64 on a windows 8.1 machine.
Thanks for reading!</p>
