From 3728833349fa1067781328f01e7c27148d241357 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 31 Jul 2015 10:54:19 +0500 Subject: [PATCH] lodash: changed _.curry() and added _.curryRight() methods --- lodash/lodash-tests.ts | 24 ++++++++++++++++++------ lodash/lodash.d.ts | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index afdc3c0e8..482cd3a88 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -817,13 +817,25 @@ result = <() => boolean>_.createCallback(createCallbackObj); result = <_.LoDashObjectWrapper<() => any>>_('name').createCallback(); result = <_.LoDashObjectWrapper<() => boolean>>_(createCallbackObj).createCallback(); -result = _.curry(function (a: any, b: any, c: any) { - console.log(a + b + c); -}); +// _.curry +var testCurryFn = (a: number, b: number, c: number) => [a, b, c]; +interface TestCurryResultFn { + (...args: number[]): number[] | TestCurryResultFn; +} +result = _.curry(testCurryFn)(1, 2, 3); +result = _.curry(testCurryFn)(1); +result = _(testCurryFn).curry().value()(1, 2, 3); +result = _(testCurryFn).curry().value()(1); -result = <_.LoDashObjectWrapper>_(function (a: any, b: any, c: any) { - console.log(a + b + c); -}).curry(); +// _.curryRight +var testCurryRightFn = (a: number, b: number, c: number) => [a, b, c]; +interface TestCurryRightResultFn { + (...args: number[]): number[] | TestCurryRightResultFn; +} +result = _.curryRight(testCurryRightFn)(1, 2, 3); +result = _.curryRight(testCurryRightFn)(1); +result = _(testCurryRightFn).curryRight().value()(1, 2, 3); +result = _(testCurryRightFn).curryRight().value()(1); declare var source: any; result = _.debounce(function () { }, 150); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c75ca9979..bf1835fc9 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5325,24 +5325,44 @@ declare module _ { //_.curry interface LoDashStatic { /** - * Creates a function which accepts one or more arguments of func that when invoked either - * executes func returning its result, if all func arguments have been provided, or returns - * a function that accepts one or more of the remaining func arguments, and so on. The arity - * of func can be specified if func.length is not sufficient. - * @param func The function to curry. - * @param arity The arity of func. - * @return The new curried function. - **/ - curry( + * Creates a function that accepts one or more arguments of func that when called either invokes func returning + * its result, if all func arguments have been provided, or returns a function that accepts one or more of the + * remaining func arguments, and so on. The arity of func may be specified if func.length is not sufficient. + * @param func The function to curry. + * @param arity The arity of func. + * @return Returns the new curried function. + */ + curry( func: Function, - arity?: number): Function; + arity?: number): TResult; } interface LoDashObjectWrapper { /** * @see _.curry **/ - curry(arity?: number): LoDashObjectWrapper; + curry(arity?: number): LoDashObjectWrapper; + } + + //_.curryRight + interface LoDashStatic { + /** + * This method is like _.curry except that arguments are applied to func in the manner of _.partialRight + * instead of _.partial. + * @param func The function to curry. + * @param arity The arity of func. + * @return Returns the new curried function. + */ + curryRight( + func: Function, + arity?: number): TResult; + } + + interface LoDashObjectWrapper { + /** + * @see _.curryRight + **/ + curryRight(arity?: number): LoDashObjectWrapper; } //_.debounce