Proposal: new syntax for pattern matching of maps

40 views
Skip to first unread message

Mário Guimarães

unread,
May 20, 2019, 7:10:41 PM5/20/19
to elixir-lang-core
Hi,

what if Elixir supported this new syntax for pattern matching of maps, in which for example,

%{key1, key2}

would be the same as

%{key1: key1, key2: key2}

Also, the following

%{key1, ^key2}

would be the same as

%{key1: key1, key2: ^key2}

What do you think?

I find myself repeating this pattern many times, and I believe this can make the code more succinct and clear.

Obviously this would only work when key1 and key2 are variable names, not expressions.

Probably this has been proposed before, ... but I do not know.

What do you think?

Thanks

José Valim

unread,
May 20, 2019, 8:10:37 PM5/20/19
to elixir-l...@googlegroups.com
Hi Mario,

This has been proposed a couple times in the past and there are some libraries today that provide a similar syntax. You can search the google groups via the web interface to find previous discussions and the rationale for not including it in the language. There were probably discussions in the forum too.
--


José Valim
Skype: jv.ptec
Founder and Director of R&D

Mário Guimarães

unread,
May 21, 2019, 5:04:28 AM5/21/19
to elixir-lang-core
Hi José,

sorry for duplicating this again.

I have just read your opinion here and it makes sense.

Thanks
Mário
Reply all
Reply to author
Forward
0 new messages