Personally I like the "create" and "update" shorthand syntaxes, but I guess
that goes against the goal of writing explicit elixir code. As for those
against it, I find their argument weak since every developer/team is open
to following their own style guides without anyone forcing them to do
otherwise but I do get where they are coming from.
On Thursday, June 1, 2017 at 9:29:39 AM UTC-4, José Valim wrote:
>
> This discussion comes up from time to time, so I would recommend seeing
> the previous discussions. There are many in favor of this feature and many
> that do not appreciate the loss in readability.
>
> Although I have almost no reservations against using a shorthand syntax
> for matching, I find it too cryptic for creates:
>
> %{name, age} #=> %{name: name, age: age}
>
>
> And even more for updates:
>
> %{user | name, age} #=> %{user | name: name, age: age}
>
>
> The choice is in supporting the syntax only for matching but that makes
> the feature somewhat inconsistent.
>
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
> On Thu, Jun 1, 2017 at 10:50 AM, FTS <[email protected] <javascript:>>
> wrote:
>
>> FYI: https://github.com/whatyouhide/short_maps
>>
>> On Thu, Jun 1, 2017 at 3:04 PM, Sheharyar Naseer <[email protected]
>> <javascript:>> wrote:
>>
>>> Most Elixir devs will agree with me, that when pattern matching on Maps,
>>> the variable names are usually the same as the keys:
>>>
>>> def some_method(%{user: %{id: id, email: email}, action: action, message:
>>> message}) do
>>> # do something
>>> end
>>>
>>>
>>> I propose another way to pattern match Key-Value pairs in Maps, using the
>>> variable names alone (Similar to how you destructure objects in ES6
>>> <https://gist.github.com/mikaelbr/9900818#file-destructuring-js-L66>):
>>>
>>> %{ a, b } = %{a: 1, b: 2}
>>>
>>> and
>>>
>>> def some_method(%{user: %{ id, email }, action, message}) do
>>> # do something
>>> end
>>>
>>> If this makes sense to others, I'm can try doing this and send a PR (if
>>> someone can point me in the right direction 😊).
>>>
>>> --
>>> 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 [email protected] <javascript:>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/elixir-lang-core/1d79fb43-8385-46d2-b4c9-8acca1c2407f%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/elixir-lang-core/1d79fb43-8385-46d2-b4c9-8acca1c2407f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/elixir-lang-core/CAHsFyS8as8QDZd8T1wk-_CrGBnzDteNgfNAidG4JS7q_z8%2BLNg%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/elixir-lang-core/CAHsFyS8as8QDZd8T1wk-_CrGBnzDteNgfNAidG4JS7q_z8%2BLNg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/99d375e3-31c5-4b79-ae11-64733ff78b6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.