[erlang-questions] pattern matching with maps in function heads

Richard A. O'Keefe ok@REDACTED
Mon Nov 2 01:36:57 CET 2015


On 30/10/2015, at 5:57 am, Martin Koroudjiev <mrtndimitrov@REDACTED> wrote:

> Hello and thank,
> 
> Yes, I know about the maps module but was trying to explore the map
> syntax and use pattern matching. I, actually, am not trying to match on
> the value but on the key name. I thought Attrib will take the value of
> the first argument and this value will be used as key name in the map.

For this particular example, it is 'obvious' how to
schedule the steps of pattern matching to make it work.
It's not so obvious in the general case.  Consider

  f(#{X := X}) -> X.

(And that's one of the easier tricky questions!)
Map matching may well be generalised at some later
time when the pitfalls are better understood.




More information about the erlang-questions mailing list