I'm new to CoffeeScript, so I'm just using this to document idioms that I am using. Suggestions / improvements are very welcome.
increment = do ->
x = 0
(amount) ->
x += amount
noop = (->)
or as a lambda...
foo(->)
CoffeeScript supports destructuring assignment, which makes named params a breeze:
foo = ({param1, param2}) ->
console.log(param1, param2)
# ... elsewhere
foo({
param1: 'value'
param2: 'another value'
})
CoffeeScript supports rest params, which means that you can use ...
to create an array of the remaining parameters. Useful.
foo = (fn, context, args...) ->
args.unshift('foo')
fn.apply(context, args)
This patches a common problem.
for own key, stream of streams
stream.end = (->)
Which replaces the following JavaScript:
var key, stream = highland();
for (key in streams) {
if ( streams.hasOwnProperty(key) ) {
stream = streams[key];
stream.end = (function() {});
}
}