Skip to content

Support list comprehensions #415

Closed
Closed
@DartBot

Description

@DartBot

This issue was originally filed by adblockforc...@gmail.com


Support list comprehensions a la Python, or else list somewhere why you won't support them.

Rationale:
 - They are voted the number one favorite language feature of Pythonistas, which will help with adoption and evangelism.
 - They can be implemented as syntactic sugar and require no new keywords.
 - They allow for clearer and shorter looping constructs.
 - They allow for a functional style without explicit use of map() and filter().

You will gain converts who love list comprehensions and are tired of them not existing in JavaScript.

I'm sure you know the format, but for everyone else: the list comprehension

  [ expr1 for a in list1 if expr2 ]

is roughly equivalent to the JavaScript

  (function() {
    var result = [];
    for (var i = 0; i < list1.length; i++) {
      if (expr2)
        result.append(expr1); // can refer to a
    return result;
  )()

and multiple 'for' subclauses are supported.

Metadata

Metadata

Assignees

Labels

area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-not-plannedClosed as we don't intend to take action on the reported issuetype-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions