Skip to content

Instantly share code, notes, and snippets.

Created October 30, 2016 16:07
Show Gist options
  • Save anonymous/c09f4f4a9b5401a43aa08b1c6722ff4d to your computer and use it in GitHub Desktop.
Save anonymous/c09f4f4a9b5401a43aa08b1c6722ff4d to your computer and use it in GitHub Desktop.
null created by anonymous - https://repl.it/EJs8/9
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