jashkenas/coffee-script — Issue #2124: Terser syntax for common comprensions
Author: mullr
Created: 2012-02-17 23:07:09+00:00
State: open

It seems very common to write an array comprehension which does the equivalent of a map:

data = [1,2,3]
inc = (a) -> a+1
result = (inc(x) for x in data)

But it's kind of obnoxious typing that x twice when you don't have to do anything to it. It would be cool to have a shortcut for that case:

result = (inc for data)

Maybe a bit more syntax would be appropriate:

result = (inc for all data)

This would clearly only work with 1-arity functions. But this is case is so common that it may be worth it.

This can be done today using the underscore.js map function, but it doesn't compile down to loops like array comprehensions do.