Array comprehensions shorter syntax (?)

Dmitry A. Soshnikov dmitry.soshnikov at gmail.com
Sun May 29 06:06:09 PDT 2011


On 29.05.2011 16:18, Jose Antonio Perez wrote:
> 2011/5/29 Dmitry A. Soshnikov <dmitry.soshnikov at gmail.com 
> <mailto:dmitry.soshnikov at gmail.com>>
>
>     Hi,
>
>     Don't get this proposal as a bikesheding, just an idea in case if
>     arrow functions will win the block-functions.
>
>     What about to make a sugar for Array comprehensions based also on
>     arrow syntax? The same as in Erlang:
>
>     let data = [1, 2, 3, 4, 5];
>
>     let squares = [x * x | x <- data, x > 3]; // [16, 25]
>
>
> Basically you are proposing bring in  Haskell's syntax for comprehensions

Yeah, here I found a list of other syntax, including math root from sets 
theory: http://en.wikipedia.org/wiki/List_comprehension And taking into 
account to accept arrow functions, I think this Erlang's/Haskell's <- 
notation fits nice and avoids the long for-loop and if-statement 
constructions. Besides, the ability to traverse directly over values 
without specifying it explicitly via generator IMO is also a good thing.

>     3. Of course it's assumed that we can destructure elements in such
>     array comprehensions:
>
>     let users = [
>      {name: "Alex", age: 31},
>      {name: "John", age: 25},
>      {name: "Mark", age: 33}
>     ];
>
>     let names = [name | {name, age} <- users, age > 30]; // ["Alex",
>     "Mark"]
>
>
> This form of located flat pattern matching is good.
>

It should follow from the shorter notation of destructuring, and yeah, I 
also think it's good.

Dmitry.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110529/684b5eec/attachment.html>


More information about the es-discuss mailing list