Last active
December 25, 2015 00:49
-
-
Save mattbierner/6891052 to your computer and use it in GitHub Desktop.
Javascript placeholder currying
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 _ = {}; | |
| var placeholder = function(f /*, ...*/) { | |
| var bound = [].slice.call(arguments, 1); | |
| return function(/*...*/) { | |
| var indx = 0; | |
| return f.apply(f, [].reduce.call(arguments, function(p, c) { | |
| while (indx in bound) { | |
| var val = bound[indx]; | |
| if (val === _) | |
| break; | |
| p[indx] = val; | |
| ++indx; | |
| } | |
| p[indx] = c; | |
| ++indx; | |
| return p; | |
| }, bound.slice())); | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment