lodash: added _.rearg() method

This commit is contained in:
Ilya Mochalov
2015-08-07 23:38:16 +05:00
parent a95ee80de0
commit 1e97f548e3
2 changed files with 40 additions and 0 deletions
+10
View File
@@ -977,6 +977,16 @@ var optionsPartialRight = {
defaultsDeep(optionsPartialRight, _.templateSettings);
//_.rearg
var testReargFn = (a: string, b: string, c: string) => [a, b, c];
interface TestReargResultFn {
(b: string, c: string, a: string): string[];
}
result = <string[]>(_.rearg<TestReargResultFn>(testReargFn, 2, 0, 1))('b', 'c', 'a');
result = <string[]>(_.rearg<TestReargResultFn>(testReargFn, [2, 0, 1]))('b', 'c', 'a');
result = <string[]>(_(testReargFn).rearg<TestReargResultFn>(2, 0, 1).value())('b', 'c', 'a');
result = <string[]>(_(testReargFn).rearg<TestReargResultFn>([2, 0, 1]).value())('b', 'c', 'a');
//_.restParam
var testRestParamFn = (a: string, b: string, c: number[]) => a + ' ' + b + ' ' + c.join(' ');
interface testRestParamFunc {
+30
View File
@@ -5654,6 +5654,36 @@ declare module _ {
...args: any[]): Function;
}
//_.rearg
interface LoDashStatic {
/**
* Creates a function that invokes func with arguments arranged according to the specified indexes where the
* argument value at the first index is provided as the first argument, the argument value at the second index
* is provided as the second argument, and so on.
* @param func The function to rearrange arguments for.
* @param indexes The arranged argument indexes, specified as individual indexes or arrays of indexes.
* @return Returns the new function.
*/
rearg<TResult extends Function>(func: Function, indexes: number[]): TResult;
/**
* @see _.rearg
*/
rearg<TResult extends Function>(func: Function, ...indexes: number[]): TResult;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.rearg
*/
rearg<TResult extends Function>(indexes: number[]): LoDashObjectWrapper<TResult>;
/**
* @see _.rearg
*/
rearg<TResult extends Function>(...indexes: number[]): LoDashObjectWrapper<TResult>;
}
//_.restParam
interface LoDashStatic {
/**