Skip to content

Instantly share code, notes, and snippets.

@fuqcool
Created November 24, 2015 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuqcool/fe43cacef1ff87c36376 to your computer and use it in GitHub Desktop.
Save fuqcool/fe43cacef1ff87c36376 to your computer and use it in GitHub Desktop.
/* Mimics the way Haskell function works */
function cascade(fn, n) {
return (function helper(args) {
return function () {
args = args.concat(Array.prototype.slice.call(arguments))
return (args.length >= n) ? fn.apply(null, args) : helper(args)
}
}([]))
}
@fuqcool
Copy link
Author

fuqcool commented Nov 24, 2015

Example

var add = cascade(function (a, b) {return a + b}, 2)
console.assert(add(1)(2) === 3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment