Array comprehensions shorter syntax (?)

Jose Antonio Perez joseanpg at gmail.com
Sun May 29 05:18:41 PDT 2011


2011/5/29 Dmitry A. Soshnikov <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


> 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.

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


More information about the es-discuss mailing list