Merge pull request #5661 from chrootsu/lodash-at

lodash: changed _.at() method
This commit is contained in:
Masahiro Wakame
2015-09-08 23:07:35 +09:00
2 changed files with 33 additions and 42 deletions
+13 -2
View File
@@ -443,8 +443,19 @@ result = <number[]>_([1, 2]).zipWith<number>([1, 2], [1, 2], [1, 2], [1, 2], [1,
* Collection *
**************/
result = <string[]>_.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
result = <string[]>_.at(['moe', 'larry', 'curly'], 0, 2);
// _.at
{
let testAtArray: TResult[];
let testAtList: _.List<TResult>;
let testAtDictionary: _.Dictionary<TResult>;
let result: TResult[];
result = _.at<TResult>(testAtArray, 0, '1', [2], ['3'], [4, '5']);
result = _.at<TResult>(testAtList, 0, '1', [2], ['3'], [4, '5']);
result = _.at<TResult>(testAtDictionary, 0, '1', [2], ['3'], [4, '5']);
result = _(testAtArray).at(0, '1', [2], ['3'], [4, '5']).value();
result = _(testAtList).at<TResult>(0, '1', [2], ['3'], [4, '5']).value();
result = _(testAtDictionary).at<TResult>(0, '1', [2], ['3'], [4, '5']).value();
}
result = <boolean>_.contains([1, 2, 3], 1);
result = <boolean>_.contains([1, 2, 3], 1, 2);
+20 -40
View File
@@ -2063,51 +2063,31 @@ declare module _ {
//_.at
interface LoDashStatic {
/**
* Creates an array of elements from the specified indexes, or keys, of the collection.
* Indexes may be specified as individual arguments or as arrays of indexes.
* @param collection The collection to iterate over.
* @param indexes The indexes of collection to retrieve, specified as individual indexes or
* arrays of indexes.
* @return A new array of elements corresponding to the provided indexes.
**/
* Creates an array of elements corresponding to the given keys, or indexes, of collection. Keys may be
* specified as individual arguments or as arrays of keys.
*
* @param collection The collection to iterate over.
* @param props The property names or indexes of elements to pick, specified individually or in arrays.
* @return Returns the new array of picked elements.
*/
at<T>(
collection: Array<T>,
indexes: number[]): T[];
collection: List<T>|Dictionary<T>,
...props: Array<number|string|Array<number|string>>
): T[];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.at
**/
at<T>(
collection: List<T>,
indexes: number[]): T[];
* @see _.at
*/
at(...props: Array<number|string|Array<number|string>>): LoDashArrayWrapper<T>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.at
**/
at<T>(
collection: Dictionary<T>,
indexes: number[]): T[];
/**
* @see _.at
**/
at<T>(
collection: Array<T>,
...indexes: number[]): T[];
/**
* @see _.at
**/
at<T>(
collection: List<T>,
...indexes: number[]): T[];
/**
* @see _.at
**/
at<T>(
collection: Dictionary<T>,
...indexes: number[]): T[];
* @see _.at
*/
at<TResult>(...props: Array<number|string|Array<number|string>>): LoDashArrayWrapper<TResult>;
}
//_.contains