stick-js
Version:
Fast toolkit for functional programming in JS. Provides idioms for referentially transparent expressions, clear separation of mutable and immutable operations, object factories, function calls based on English grammar, and pipe & compose operators.
5 lines • 1.01 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});exports.roll=exports.recurry=void 0;// --- see index.js for docs.
var roll=exports.roll=function roll(f){return function(){var g=f;for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}for(var _i=0,_args=args;_i<_args.length;_i++){var i=_args[_i];g=g(i);}return g;};};/* A surprising result is that `recurry` actually works fine if `n` is exactly one smaller than the
* necessary arity.
* So, this check is not strictly necessary, but is intended to avoid confusion down the road.
*/var check_dn=function check_dn(dn,f){if(dn>=0)return;throw new Error("recurry: arity error (perhaps you should call `recurry` "+"with a higher value for `n`; `f` was "+f.toString());};var _recurry=exports.recurry=function recurry(n){return function(f){return function(){var rolled=roll(f).apply(void 0,arguments);var dn=n-arguments.length;check_dn(dn,f);return dn<1?rolled:_recurry(dn)(rolled);};};};