From 5d971a1007065c3f0e9320bad4353ee1de2f48f5 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 25 Jul 2015 16:58:29 +0500 Subject: [PATCH] lodash: added _.modArgs() method --- lodash/lodash-tests.ts | 21 +++++++++++++++++++++ lodash/lodash.d.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 627dda565..85f80c09b 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -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 = _.modArgs((x: string, y: string) => [x, y], modArgsFn1, modArgsFn2); +result = result(1, true); + +result = _.modArgs((x: string, y: string) => [x, y], [modArgsFn1, modArgsFn2]); +result = result(1, true); + +result = _((x: string, y: string) => [x, y]).modArgs(modArgsFn1, modArgsFn2).value(); +result = result(1, true); + +result = _((x: string, y: string) => [x, y]).modArgs([modArgsFn1, modArgsFn2]).value(); +result = result(1, true); + var initialize = _.once(function () { }); initialize(); initialize();'' diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 7bc1df648..62c1ea0d9 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -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( + func: T, + ...transforms: Function[] + ): TResult; + + /** + * @see _.modArgs + */ + modArgs( + func: T, + transforms: Function[] + ): TResult; + } + + interface LoDashObjectWrapper { + /** + * @see _.modArgs + */ + modArgs(...transforms: Function[]): LoDashObjectWrapper; + + /** + * @see _.modArgs + */ + modArgs(transforms: Function[]): LoDashObjectWrapper; + } + //_.once interface LoDashStatic { /**