jashkenas/coffee-script — Issue #1954: Add for-yield syntax
Author: paulmillr
Created: 2011-12-20 16:13:57+00:00
State: open

This is a common idiom:

```coffeescript
getSourceData = (data) ->
result = []
for destinationFile in data
for sourceFile in destinationFile.sourceFiles
result.push sourceFile.data
result
```

I propose to introduce a simple `for-yield` syntax (the one *Scala* has) that would allow users to rewrite the example as

```coffeescript
getSourceData = (destFiles) ->
for (
destinationFile <- destFiles
sourceFile <- destinationFile.sourceFiles
) sourceFile.data
```

More complex example:

```coffeescript
fn = (data) ->
result = []
for a in data
for b in a.bb
for c in b.cc
for d in c.dd
for e in d.ee
result.push e
result

# becomes
fn = (data) ->
for (
a <- data
b <- a.bb
c <- b.cc
d <- c.dd
e <- d.ee
) e
```