You just need to use parenthesis, ()
, instead of square brackets, []
.
From a REPL:
coffee> ([i, 1] for i in [1])
[ [ 1, 1 ] ]
coffee> [[i, 1] for i in [1]]
[ [ [ 1, 1 ] ] ]
you can see that using the square brackets, as you would in Python, puts the generating expression inside of an extra list.
This is because the parenthesis, ()
are actually only there in CoffeeScript for when you want to assign the expression to a variable, so:
coffee> a = ([i, 1] for i in [1])
[ [ 1, 1 ] ]
coffee> a[0][1]
1
coffee> b = [i, 1] for i in [1]
[ [ 1, 1 ] ]
coffee> b[0][1]
undefined
Also, see the CoffeeScript Cookbook.