Skip to content

Instantly share code, notes, and snippets.

@nakamura-to
Created March 29, 2012 14:36
Show Gist options
  • Save nakamura-to/2238031 to your computer and use it in GitHub Desktop.
Save nakamura-to/2238031 to your computer and use it in GitHub Desktop.
F#-like partial function application in CoffeeScript
fun = (f) ->
curry = () ->
if (arguments.length < f.length)
args = Array.prototype.slice.call(arguments);
() ->
curry.apply(this, args.concat(Array.prototype.slice.call(arguments)));
else
f.apply(this, arguments)
add = fun (a, b, c) -> a + b + c
console.log(add(1, 2, 3)); # 6
console.log(add(1)(2, 3)); # 6
console.log(add(1)(2)(3)); # 6
console.log(add(1, 2)(3)); # 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment