Skip to content

Commit

Permalink
_ -> Function._
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Oct 30, 2009
1 parent a187d89 commit e369b8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions FuncTools.js
Expand Up @@ -125,26 +125,27 @@ function $get(first, prop) {
};

/*
Constant: _
Constant: Function._
To denote a value to be filled in curried function.
See Also:
<curry>
<Function.curry>
*/
var _ = {};
Function._ = {};

(function() {
function argmerge(a, b) {
var result = [];
for(var i = 0, len = Math.max(a.length, b.length); i < len; i++) {
result[i] = (b[i] == _) ? a[i] || _ : (b[i] !== undefined && b[i]) || a[i];
result[i] = (b[i] == Function._) ? a[i] || Function._ : (b[i] !== undefined && b[i]) || a[i];
}
return result;
};
Function.implement({
/*
Function: Function.exec
Takes a list of arguments a creates a function
which a takes a function and call it with those
which a takes a function and calls it with those
arguments. If called with a function as the first
argument, executes the function immediately.
Expand Down Expand Up @@ -329,6 +330,7 @@ Function.implement({
supplied.
(start code)
var _ = Function._;
function abc(a, b, c) { return a + b + c; };
var curried = abc.curry(null, _, _, 3);
curried = curried(1);
Expand All @@ -337,10 +339,10 @@ Function.implement({
*/
curry: function(bind) {
var self = this, arglist = Function.arglist(this), args = $A(arguments).rest();
args = argmerge($repeat(arglist.length, _), args);
args = argmerge($repeat(arglist.length, Function._), args);
return function() {
var fargs = argmerge(args, $A(arguments));
if(fargs.length == arglist.length && fargs.every(Function.not(Function.eq(_)))) {
if(fargs.length == arglist.length && fargs.every(Function.not(Function.eq(Function._)))) {
return self.apply(bind, fargs);
} else {
return self.curry.apply(self, [bind].extend(fargs));
Expand Down
1 change: 1 addition & 0 deletions readme.textile
Expand Up @@ -28,6 +28,7 @@ partialFn(4); // 12
However you don't always have control of the argument order- i.e. using someone else's library. If for some reason you need to supply arguments out of order you should use *Function.curry*:

<pre>
var _ = Function._;
function abc(a, b, c) { return a + b + c; };
var curried = abc.curry(null, _, _, 3);
curried = curried(1);
Expand Down

0 comments on commit e369b8e

Please sign in to comment.