Merge pull request #5156 from chrootsu/lodash-curry-curryRight

lodash: changed _.curry() and added _.curryRight() methods
This commit is contained in:
Masahiro Wakame
2015-08-03 22:29:55 +09:00
2 changed files with 49 additions and 17 deletions
+18 -6
View File
@@ -813,13 +813,25 @@ result = <() => boolean>_.createCallback(createCallbackObj);
result = <_.LoDashObjectWrapper<() => any>>_('name').createCallback();
result = <_.LoDashObjectWrapper<() => boolean>>_(createCallbackObj).createCallback();
result = <Function>_.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 = <number[]>_.curry<TestCurryResultFn>(testCurryFn)(1, 2, 3);
result = <TestCurryResultFn>_.curry<TestCurryResultFn>(testCurryFn)(1);
result = <number[]>_(testCurryFn).curry<TestCurryResultFn>().value()(1, 2, 3);
result = <TestCurryResultFn>_(testCurryFn).curry<TestCurryResultFn>().value()(1);
result = <_.LoDashObjectWrapper<Function>>_(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 = <number[]>_.curryRight<TestCurryRightResultFn>(testCurryRightFn)(1, 2, 3);
result = <TestCurryRightResultFn>_.curryRight<TestCurryRightResultFn>(testCurryRightFn)(1);
result = <number[]>_(testCurryRightFn).curryRight<TestCurryRightResultFn>().value()(1, 2, 3);
result = <TestCurryRightResultFn>_(testCurryRightFn).curryRight<TestCurryRightResultFn>().value()(1);
declare var source: any;
result = <Function>_.debounce(function () { }, 150);
+31 -11
View File
@@ -5335,24 +5335,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<TResult extends Function>(
func: Function,
arity?: number): Function;
arity?: number): TResult;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.curry
**/
curry(arity?: number): LoDashObjectWrapper<Function>;
curry<TResult extends Function>(arity?: number): LoDashObjectWrapper<TResult>;
}
//_.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<TResult extends Function>(
func: Function,
arity?: number): TResult;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.curryRight
**/
curryRight<TResult extends Function>(arity?: number): LoDashObjectWrapper<TResult>;
}
//_.debounce