Skip to content

Instantly share code, notes, and snippets.

@pablodenadai
Forked from lovasoa/partial-evaluation.js
Created February 9, 2017 00:55
Show Gist options
  • Save pablodenadai/f82d7d13d6e848d80162eeafeb541991 to your computer and use it in GitHub Desktop.
Save pablodenadai/f82d7d13d6e848d80162eeafeb541991 to your computer and use it in GitHub Desktop.
Partial-evaluation for javascript.
/** 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