phiggins42 (owner)

Revisions

gist: 222589 Download_button fork
public
Public Clone URL: git://gist.github.com/222589.git
Embed All Files: show embed
d.compose.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(function(d){
 
d.compose = function(/* Function... */){
// summary: Returns the composition of a list of functions.
//
// description:
// Returns the composition of a list of functions, where each
// function consumes the return value of the function that follows.
//
// additionally, if one of the functions returns an array, the values
// of that array are passed to the next function in the composition
// as positional arguments.
//
// example:
// | var greet = function(name){ return "Hi: " + name; };
// | var exclaim = function(statement){ return statement + "!"; };
// | var welcome = dojo.compose(greet, exclaim);
// | welcome("Pete");
// | // Hi: Pete!
 
var list = d._toArray(arguments);
return function(){ // function
var a = arguments;
d.forEach(list, function(fn){
a = fn.apply(this, d.isArrayLike(a) ? a : [a]);
});
return a;
}
}
 
})(dojo);