Last active
December 28, 2023 05:56
-
-
Save lovasoa/e9c51b84ead1ae0b2659 to your computer and use it in GitHub Desktop.
Partial-evaluation for javascript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** pe | |
* @argument f: the multiple-argument function to turn into a partially-evaluatable | |
* @returns : A single-argument function that applies its argument as the first argument of f, and returns the partially-evaluated function | |
* @exemple: pe((a,b)=>a+b)(9)(1) === 10 | |
*/ | |
function pe(f, context, args) { | |
if(!args) args = []; | |
if (args.length === f.length) return f.apply(context, args); | |
return function partial (a) { | |
var args_copy = args.concat.apply(args, arguments); | |
return pe(f, context, args_copy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment