Merge pull request #5189 from chrootsu/lodash-fill

lodash: changed _.fill() method
This commit is contained in:
Masahiro Wakame 2015-08-04 00:29:44 +09:00
commit 91c19bc506
2 changed files with 57 additions and 17 deletions

View File

@ -177,6 +177,16 @@ result = <number[]>_.tail([1, 2, 3], (num) => num < 3)
result = <IFoodOrganic[]>_.tail(foodsOrganic, 'test')
result = <IFoodType[]> _.tail(foodsType, { 'type': 'value' })
// _.fill
var testFillArray = [1, 2, 3];
var testFillList: _.List<number> = {0: 1, 1: 2, 2: 3, length: 3};
result = <string[]>_.fill<string>(testFillArray, 'a', 0, 3);
result = <_.List<string>>_.fill<string>(testFillList, 'a', 0, 3);
result = <number[]>_(testFillArray).fill<number>(0, 0, 3).value();
result = <_.List<number>>_(testFillList).fill<number>(0, 0, 3).value();
result = <number>_.findIndex(['apple', 'banana', 'beet'], function (f) {
return /^b/.test(f);
});

64
lodash/lodash.d.ts vendored
View File

@ -2491,24 +2491,54 @@ declare module _ {
collection: Dictionary<T>,
whereValue: W): boolean;
}
//_.fill
interface LoDashStatic {
/**
* Fills elements of array with value from start up to, but not including, end.
*
* Note: This method mutates array.
*
* @param array (Array): The array to fill.
* @param value (*): The value to fill array with.
* @param [start=0] (number): The start position.
* @param [end=array.length] (number): The end position.
* @return (Array): Returns array.
**/
fill<T>(
array: Array<any>,
value: any,
start?: number,
end?: number): Array<any>;
/**
* Fills elements of array with value from start up to, but not including, end.
*
* Note: This method mutates array.
*
* @param array (Array): The array to fill.
* @param value (*): The value to fill array with.
* @param [start=0] (number): The start position.
* @param [end=array.length] (number): The end position.
* @return (Array): Returns array.
*/
fill<TResult>(
array: any[],
value: any,
start?: number,
end?: number): TResult[];
/**
* @see _.fill
*/
fill<TResult>(
array: List<any>,
value: any,
start?: number,
end?: number): List<TResult>;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.fill
*/
fill<TResult>(
value: any,
start?: number,
end?: number): LoDashArrayWrapper<TResult>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.fill
*/
fill<TResult>(
value: any,
start?: number,
end?: number): LoDashObjectWrapper<List<TResult>>;
}
//_.filter