4 ms·
If you're into one-liners, CoffeeScript is your friend :) foo = (n) -> (-> i) for i in [0..n]
by mendelk 12y ago
If you're into one-liners, CoffeeScript is your friend :)
foo = (n) -> (-> i) for i in [0..n]
- rmrfrmrf 12y agoClose, but I checked it and the value of `i` won't bind to the function. You also have to use `...` (exclusive range) instead of `..` to prevent an off-by-one error. Here's one way: foo = (n) -> ((a) -> a).bind(null, i) for i in [0...n] Here's a more esoteric/bad style (but cute) way: foo = (n) -> (-> +@).bind i for i in [0...n]
- alxndr 12y agoI've been preferring explicit `map()`s in my CoffeeScript for exactly that reason.