Sdk: Destructuring Assignment

Created on 12 Oct 2011  路  17Comments  路  Source: dart-lang/sdk

_This issue was originally filed by binary...@binarysplit.com_


Destructuring Assignment is a feature of Javascript 1.7. MDC has a good guide: https://developer.mozilla.org/en/New_in_JavaScript_1.7#Destructuring_assignment_%28Merge_into_own_page.2Fsection%29

Essentially, it provides a significant reduction in code size when dealing with multiple return values, iteration over zipped arrays or arrays of objects, and shuffles.

I suspect this feature is already in the Dart roadmap (due to it already being in Javascript). I just want to make sure it's publicly acknowledged and open for discussion.

area-language closed-not-planned type-enhancement

Most helpful comment

9 years later, end of 2020 and we still don't have it lel

All 17 comments

_This comment was originally written by binary...@binarysplit.com_


Duplicate of Issue #35( http://code.google.com/p/dart/issues/detail?id=35 ).

Which name is better? I find "Pattern Matching" to be somewhat ambiguous, as it shares a name with Scala's "match" statement( http://www.scala-lang.org/node/120 ) and Perl's RegExs.

_This comment was originally written by [email protected]_


_Added Area-Language, Triaged labels._

_This comment was originally written by [email protected]_


Issue #35 has been merged into this issue.

It is possible we'll do something in this space in time. Please note the difference between a feature request and a defect when filing bugs.


_Set owner to @gbracha._
_Removed Type-Defect label._
_Added Type-Enhancement label._

_This comment was originally written by [email protected]_


Issue #97 has been merged into this issue.

_Added apr30-triage label._

_Removed apr30-triage label._

_Added triage1 label._

Pattern matching is more in the right direction.


_Removed triage1 label._
_Added WontFix label._

_This comment was originally written by devin.t...@gmail.com_


Any link to the relevant issue for implementing pattern matching?

Issue #10267 has been merged into this issue.

see this issue for pattern matching: https://code.google.com/p/dart/issues/detail?id=2949

_This comment was originally written by @simonpai_


Pattern matching is a different idea and it does not cover destructing assignment. It's literally wrong to close this ticket because of pattern matching.

_This comment was originally written by @tomyeh_


Destructing assignment is similar to the parallel assignment in Ruby (http://codeofpractice.blogspot.tw/2010/05/parallel-assignment-in-ruby.html), right?

It is quite helpful if a function needs to return two or more objects of different types (strong typed and no class required). I don't see if pattern matching can help here.

_This comment was originally written by tjp...@gmail.com_


Agreed with #颅13. Destructuring assignment is a useful _part_ of common pattern matching features. It's very useful elsewhere, too.

_This comment was originally written by unis...@gmail.com_


Clojure also supports pretty advanced destructuring:
http://clojure.org/special_forms#Special%20Forms--Binding%20Forms%20%28Destructuring%29
http://blog.jayfields.com/2010/07/clojure-destructuring.html

9 years later, end of 2020 and we still don't have it lel

Was this page helpful?
0 / 5 - 0 ratings