Skip to content

Instantly share code, notes, and snippets.

@Gergling
Last active April 9, 2018 13:26
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 Gergling/f23c139c35cdc84133fed3c2f3fd068c to your computer and use it in GitHub Desktop.
Save Gergling/f23c139c35cdc84133fed3c2f3fd068c to your computer and use it in GitHub Desktop.
Putting the FUN in FUNctional programming.
// Takes a function with two parameters and allows them to be used in the format fnc(x)(y)().
function functionalise(fnc) {
return function functionalised(x) {
return function (y) {
if (y === undefined) {
return x;
} else {
return functionalised(fnc(x, y));
}
};
}
}
console.log(functionalise((x, y) => x * y)(2)(3)());
console.log(functionalise((x, y) => x + y)(2)(3)());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment