Non-binding destructuring assignment

Andreas Rossberg rossberg at google.com
Wed Apr 29 12:21:37 UTC 2015


I agree that we should have wildcard patterns. I also think that array
elisions are a non-solution, because you need a magnifier to read or count
them, and they square oddly with optional commas in the end.

/Andreas

On 29 April 2015 at 13:47, Elie Rotenberg <elie at rotenberg.io> wrote:

> Wow, thanks. I feel dumb for asking :D
>
> On Wed, Apr 29, 2015 at 1:43 PM, Sebastian McKenzie <sebmck at gmail.com>
> wrote:
>
>> The binding identifiers are optional. You can do what you want already
>> with:
>>
>> const lastOfThree = ([,, third]) => {
>>   return third;
>> }
>>
>>
>>
>>
>> On Wed, Apr 29, 2015 at 12:40 PM, Elie Rotenberg <elie at rotenberg.io>
>> wrote:
>>
>>> Using array destructuring assignment and constraining linting rules, I
>>> often find myself having to chose names for bindings I don't intent on
>>> using. I usually end up using a conventional ignore name, such as _ignore,
>>> which I "void" to shut up the linter without adding exceptions. Besides the
>>> linting problem (which can be solved by refining the linting rules), it's
>>> still a conceptually useless binding.
>>>
>>> Here's a contrived example:
>>>
>>> const lastOfThree = ([first, second, third])  => third;
>>>
>>> Which I usually end up rewriting:
>>>
>>> const lastOfThree = ([_ignore1, _ignore2, third]) => {
>>>   void _ignore1;
>>>   void _ignore2;
>>>   return third;
>>> }
>>>
>>> This problem doesn't exist when using objects, since only the fields
>>> specified on the LHS are bound.
>>>
>>> I realize the bigger topic behind non-binding match is refutable pattern
>>> matching, as per
>>> http://wiki.ecmascript.org/doku.php?id=strawman:pattern_matching, but
>>> being able to dismiss a matched (or unmatched) value from a destructuring
>>> assignment seems a very often desirable feature when programming in a
>>> functional style (eg. working with lists represented as 2-element arrays).
>>> Most functional-style languages have a non-binding matching feature.
>>>
>>> This topic has been discussed in the following topics:
>>> - https://esdiscuss.org/topic/conditional-catch
>>> - https://esdiscuss.org/notes/2014-07-30
>>> - https://esdiscuss.org/topic/conditional-catch-clause
>>>
>>> Does anyone else feel the need for a specific means of dismissing a
>>> binding from a destructuring assignment? Is pattern matching still on
>>> discussion?
>>>
>>> Regards,
>>>
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150429/eac0e732/attachment.html>


More information about the es-discuss mailing list