Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / lang / functional / curry.js @ 12

History | View | Annotate | Download (1.42 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

    
8
if(!dojo._hasResource["dojox.lang.functional.curry"]){
9
dojo._hasResource["dojox.lang.functional.curry"]=true;
10
dojo.provide("dojox.lang.functional.curry");
11
dojo.require("dojox.lang.functional.lambda");
12
(function(){
13
var df=dojox.lang.functional,ap=Array.prototype;
14
var _1=function(_2){
15
return function(){
16
var _3=_2.args.concat(ap.slice.call(arguments,0));
17
if(arguments.length+_2.args.length<_2.arity){
18
return _1({func:_2.func,arity:_2.arity,args:_3});
19
}
20
return _2.func.apply(this,_3);
21
};
22
};
23
dojo.mixin(df,{curry:function(f,_4){
24
f=df.lambda(f);
25
_4=typeof _4=="number"?_4:f.length;
26
return _1({func:f,arity:_4,args:[]});
27
},arg:{},partial:function(f){
28
var a=arguments,l=a.length,_5=new Array(l-1),p=[],i=1,t;
29
f=df.lambda(f);
30
for(;i<l;++i){
31
t=a[i];
32
_5[i-1]=t;
33
if(t===df.arg){
34
p.push(i-1);
35
}
36
}
37
return function(){
38
var t=ap.slice.call(_5,0),i=0,l=p.length;
39
for(;i<l;++i){
40
t[p[i]]=arguments[i];
41
}
42
return f.apply(this,t);
43
};
44
},mixer:function(f,_6){
45
f=df.lambda(f);
46
return function(){
47
var t=new Array(_6.length),i=0,l=_6.length;
48
for(;i<l;++i){
49
t[i]=arguments[_6[i]];
50
}
51
return f.apply(this,t);
52
};
53
},flip:function(f){
54
f=df.lambda(f);
55
return function(){
56
var a=arguments,l=a.length-1,t=new Array(l+1),i=0;
57
for(;i<=l;++i){
58
t[l-i]=a[i];
59
}
60
return f.apply(this,t);
61
};
62
}});
63
})();
64
}