-
-
Save mnxoid/f2e5b3591386b7c91f132f14e8fe5fa0 to your computer and use it in GitHub Desktop.
Placeholder + autoCurrying | created by mnxoid - https://repl.it/EJs8/9
This file contains hidden or 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
var _ = "Placeholder_secret_constant"; | |
var placeholder_support = f => | |
(...outer_args)=>{ | |
if(outer_args.filter(x=>x==_).length === 0) { | |
if(outer_args.length<f.length){ | |
while(outer_args.length<f.length)outer_args.push(_); | |
return placeholder_support(f)(...outer_args); | |
} else { | |
return f(...outer_args); | |
} | |
} | |
else { | |
var args = outer_args.map((x,i)=>[x,i]); | |
return (...inner_args)=>{ | |
inner_args.map((x,i)=>[x,args.filter(y=>y[0]==_) | |
.map(y=>y[1])[i]]) | |
.forEach(x=>{ | |
if(typeof(x[1])!=="undefined") | |
args[x[1]][0]=x[0]; | |
else | |
args.push([x[0],args.length]); | |
}); | |
return (placeholder_support(f))(...args.map(x=>x[0])); | |
}; | |
} | |
}; | |
// var f = (a,b,c,d,e)=>a+b+c+d+e; | |
// var f = (a,b,c,d,e)=>console.log(a,b,c,d,e); | |
var f = (a,b,c,...args)=>console.log(a,b,c,...args); | |
f=placeholder_support(f); | |
f(1,_,2,4,_)(3,_)(3); | |
f(1,_,_,_,_)(2)(3)(4)(5); | |
// f(1)(2)(3)(4)(5); | |
f(1)(2)(3,_)(4); | |
f(1)(2)(3,_)(4,_)(5,6); | |
f(1,_,_,_,2)(3,_,4)(5); | |
var g = (...args)=>console.log(...args); | |
g=placeholder_support(g); | |
g(_,_,2)(1)(3); | |
g(_)(1,2,3,4,5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment