mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
lodash: added _.flow() and _.flowRight() (aliases: _.backflow(), _.compose())
This commit is contained in:
+23
-15
@@ -754,6 +754,12 @@ _.forEach(saves, function (type) {
|
||||
asyncSave({ 'type': type, 'complete': done });
|
||||
});
|
||||
|
||||
// _.backflow
|
||||
var testBackflowSquareFn = (n: number) => n * n;
|
||||
var testBackflowAddFn = (n: number, m: number) => n + m;
|
||||
result = <number>_.backflow<(n: number, m: number) => number>(testBackflowSquareFn, testBackflowAddFn)(1, 2);
|
||||
result = <number>_(testBackflowSquareFn).backflow<(n: number, m: number) => number>(testBackflowAddFn).value()(1, 2);
|
||||
|
||||
var funcBind = function(greeting: string, punctuation: string) { return greeting + ' ' + this.user + punctuation; };
|
||||
var funcBound1: (punctuation: string) => any = _.bind(funcBind, { 'name': 'moe' }, 'hi');
|
||||
funcBound1('!');
|
||||
@@ -795,21 +801,11 @@ funcBindKey();
|
||||
funcBindKey = _(objectBindKey).bindKey('greet', 'hi').value();
|
||||
funcBindKey();
|
||||
|
||||
var realNameMap: { [index: string]: string; } = {
|
||||
'curly': 'jerome'
|
||||
};
|
||||
|
||||
var format = function (name: string) {
|
||||
name = realNameMap[name.toLowerCase()] || name;
|
||||
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
|
||||
};
|
||||
|
||||
var greet = function (formatted: string) {
|
||||
return 'Hiya ' + formatted + '!';
|
||||
};
|
||||
|
||||
result = <Function>_.compose(greet, format);
|
||||
result = <_.LoDashObjectWrapper<Function>>_(greet).compose(format);
|
||||
// _.compose
|
||||
var testComposeSquareFn = (n: number) => n * n;
|
||||
var testComposeAddFn = (n: number, m: number) => n + m;
|
||||
result = <number>_.compose<(n: number, m: number) => number>(testComposeSquareFn, testComposeAddFn)(1, 2);
|
||||
result = <number>_(testComposeSquareFn).compose<(n: number, m: number) => number>(testComposeAddFn).value()(1, 2);
|
||||
|
||||
var createCallbackObj: { [index: string]: string; } = { name: 'Joe' };
|
||||
result = <() => any>_.createCallback('name');
|
||||
@@ -858,6 +854,18 @@ var log = _.bind(console.log, console);
|
||||
result = <number>_.delay(log, 1000, 'logged later');
|
||||
result = <_.LoDashWrapper<number>>_(log).delay(1000, 'logged later');
|
||||
|
||||
// _.flow
|
||||
var testFlowSquareFn = (n: number) => n * n;
|
||||
var testFlowAddFn = (n: number, m: number) => n + m;
|
||||
result = <number>_.flow<(n: number, m: number) => number>(testFlowAddFn, testFlowSquareFn)(1, 2);
|
||||
result = <number>_(testFlowAddFn).flow<(n: number, m: number) => number>(testFlowSquareFn).value()(1, 2);
|
||||
|
||||
// _.flowRight
|
||||
var testFlowRightSquareFn = (n: number) => n * n;
|
||||
var testFlowRightAddFn = (n: number, m: number) => n + m;
|
||||
result = <number>_.flowRight<(n: number, m: number) => number>(testFlowRightSquareFn, testFlowRightAddFn)(1, 2);
|
||||
result = <number>_(testFlowRightSquareFn).flowRight<(n: number, m: number) => number>(testFlowRightAddFn).value()(1, 2);
|
||||
|
||||
var fibonacci = <Function>_.memoize(function (n: any): number {
|
||||
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
|
||||
});
|
||||
|
||||
Vendored
+57
-11
@@ -5183,6 +5183,21 @@ declare module _ {
|
||||
after(func: Function): LoDashObjectWrapper<Function>;
|
||||
}
|
||||
|
||||
//_.backflow
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* @see _.flowRight
|
||||
*/
|
||||
backflow<TResult extends Function>(...funcs: Function[]): TResult;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.flowRight
|
||||
**/
|
||||
backflow<TResult extends Function>(...funcs: Function[]): LoDashObjectWrapper<TResult>;
|
||||
}
|
||||
|
||||
//_.bind
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
@@ -5261,21 +5276,16 @@ declare module _ {
|
||||
//_.compose
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
compose(...funcs: Function[]): Function;
|
||||
* @see _.flowRight
|
||||
*/
|
||||
compose<TResult extends Function>(...funcs: Function[]): TResult;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.compose
|
||||
**/
|
||||
compose(...funcs: Function[]): LoDashObjectWrapper<Function>;
|
||||
* @see _.flowRight
|
||||
*/
|
||||
compose<TResult extends Function>(...funcs: Function[]): LoDashObjectWrapper<TResult>;
|
||||
}
|
||||
|
||||
//_.createCallback
|
||||
@@ -5442,6 +5452,42 @@ declare module _ {
|
||||
...args: any[]): LoDashWrapper<number>;
|
||||
}
|
||||
|
||||
//_.flow
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a function that returns the result of invoking the provided functions with the this binding of the
|
||||
* created function, where each successive invocation is supplied the return value of the previous.
|
||||
* @param funcs Functions to invoke.
|
||||
* @return Returns the new function.
|
||||
*/
|
||||
flow<TResult extends Function>(...funcs: Function[]): TResult;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.flow
|
||||
**/
|
||||
flow<TResult extends Function>(...funcs: Function[]): LoDashObjectWrapper<TResult>;
|
||||
}
|
||||
|
||||
//_.flowRight
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* This method is like _.flow except that it creates a function that invokes the provided functions from right
|
||||
* to left.
|
||||
* @param funcs Functions to invoke.
|
||||
* @return Returns the new function.
|
||||
*/
|
||||
flowRight<TResult extends Function>(...funcs: Function[]): TResult;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.flowRight
|
||||
**/
|
||||
flowRight<TResult extends Function>(...funcs: Function[]): LoDashObjectWrapper<TResult>;
|
||||
}
|
||||
|
||||
//_.memoize
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user