Hi Joshua,

This has been suggested a few times in the mailing list: 
https://groups.google.com/forum/#!searchin/elixir-lang-core/short_maps%7Csort:date

Hope that helps :)

On Tuesday, February 11, 2020 at 8:58:45 AM UTC+1, Joshua Nussbaum wrote:
>
> Hi,
>
> What do you think about adding map deconstruction syntax similar to 
> JavaScript. It would remove the need to declare the key and binding 
> variable when they are identical names.
>
> Often the map keys and binding var use the same name:
>
> # without deconstruction
> %{name: name, email: email} = user
>
> vs
>
> # with deconstruction (identical)
> %{name, email} = user
>
> This would work too for function definitions `def send_email(%{name, 
> email}) do ...`, pattern matching ` case user, do: %{name, email} -> ....` 
> as well as updates `%{user | email, name}`.
>
> It would also require updating `mix format` to replace `%{key: key}` with 
> `%{key}`
>
> Here is a prototype of the changes required to the compiler:
>
>
> https://github.com/elixir-lang/elixir/compare/master...joshnuss:map-destructure
>
> Best,
> Josh
>
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/c0e7831e-41a8-42ca-bfb1-6040f3a1d9bb%40googlegroups.com.

Reply via email to