rubico
Version:
[a]synchronous functional programming
8 lines (7 loc) • 832 B
JavaScript
/**
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
*/
const __=Symbol.for("placeholder"),_curryArity=(r,t,u)=>function(...n){const y=u.length,c=n.length,e=[];let i=-1,o=-1,f=0;for(;++i<y;){const y=u[i];if(y==__&&(o+=1)<c){const r=n[o];r==__&&(f+=1),e.push(r)}else e.push(y);if(e.length==r)return 0==f?t(...e):curryArity(r,t,e)}for(;++o<c;){const u=n[o];if(u==__&&(f+=1),e.push(u),e.length==r)return 0==f?t(...e):curryArity(r,t,e)}return curryArity(r,t,e)},curryArity=function(r,t,u){const n=u.length;if(n<r)return _curryArity(r,t,u);let y=-1;for(;++y<n;){if(u[y]==__)return _curryArity(r,t,u)}return t(...u)},curry=(r,...t)=>curryArity(r.length,r,t);curry.arity=function(r,t,...u){return curryArity(r,t,u)};export default curry;