added _.compose definition

This commit is contained in:
Brian Zengel
2013-10-18 22:33:58 -04:00
parent c9437135dd
commit 9ffae95370
2 changed files with 26 additions and 7 deletions
+16
View File
@@ -423,6 +423,22 @@ objectBindKey.greet = function(greeting) {
funcBindKey();
var realNameMap = {
'curly': 'jerome'
};
var format = function(name) {
name = realNameMap[name.toLowerCase()] || name;
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
};
var greet = function(formatted) {
return 'Hiya ' + formatted + '!';
};
var welcome = _.compose(greet, format);
welcome('curly');
+10 -7
View File
@@ -1746,6 +1746,15 @@ declare module _ {
key: string,
...args: any[]): Function;
/**
* Creates a function that is the composition of the provided functions, where each function
* consumes the return value of the function that follows. For example, composing the functions
* f(), g(), and h() produces f(g(h())). Each function is executed with the this binding of the
* composed function.
* @param funcs Functions to compose.
* @return The new composed function.
**/
export function compose(...funcs: Function[]): Function;
@@ -1928,13 +1937,7 @@ declare module _ {
fn: Function,
wrapper: (fn: Function, ...args: any[]) => any): Function;
/**
* Returns the composition of a list of functions, where each function consumes the return value of the
* function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).
* @param functions List of functions to compose.
* @return Composition of `functions`.
**/
export function compose(...functions: Function[]): Function;
/**********
* Objects *