lodash: added _.modArgs() method

This commit is contained in:
Ilya Mochalov
2015-07-28 16:32:15 +05:00
parent 73e4b46719
commit 5d971a1007
2 changed files with 56 additions and 0 deletions
+21
View File
@@ -815,6 +815,27 @@ stooge('curly');
var returnedMemoize = _.throttle(function (a: any) { return a * 5; }, 5);
returnedMemoize(4);
// _.modArgs
function modArgsFn1(n: number): string {return n.toString()}
function modArgsFn2(n: boolean): string {return n.toString()}
interface ModArgsFunc {
(x: string, y: string): string[];
}
interface ModArgsResult {
(x: number, y: boolean): string[]
}
result = <ModArgsResult>_.modArgs<ModArgsFunc, ModArgsResult>((x: string, y: string) => [x, y], modArgsFn1, modArgsFn2);
result = <string[]>result(1, true);
result = <ModArgsResult>_.modArgs<ModArgsFunc, ModArgsResult>((x: string, y: string) => [x, y], [modArgsFn1, modArgsFn2]);
result = <string[]>result(1, true);
result = <ModArgsResult>_<ModArgsFunc>((x: string, y: string) => [x, y]).modArgs<ModArgsResult>(modArgsFn1, modArgsFn2).value();
result = <string[]>result(1, true);
result = <ModArgsResult>_<ModArgsFunc>((x: string, y: string) => [x, y]).modArgs<ModArgsResult>([modArgsFn1, modArgsFn2]).value();
result = <string[]>result(1, true);
var initialize = _.once(function () { });
initialize();
initialize();''
+35
View File
@@ -5212,6 +5212,41 @@ declare module _ {
resolver?: Function): T;
}
//_.modArgs
interface LoDashStatic {
/**
* Creates a function that runs each argument through a corresponding transform function.
* @param func The function to wrap.
* @param transforms The functions to transform arguments, specified as individual functions or arrays
* of functions.
* @return Returns the new function.
*/
modArgs<T extends Function, TResult extends Function>(
func: T,
...transforms: Function[]
): TResult;
/**
* @see _.modArgs
*/
modArgs<T extends Function, TResult extends Function>(
func: T,
transforms: Function[]
): TResult;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.modArgs
*/
modArgs<TResult>(...transforms: Function[]): LoDashObjectWrapper<TResult>;
/**
* @see _.modArgs
*/
modArgs<TResult>(transforms: Function[]): LoDashObjectWrapper<TResult>;
}
//_.once
interface LoDashStatic {
/**