Merge pull request #5985 from chrootsu/lodash-take

lodash: changed _.take() method
This commit is contained in:
Masahiro Wakame
2015-10-05 22:29:15 +09:00
2 changed files with 44 additions and 39 deletions
+15 -4
View File
@@ -275,14 +275,10 @@ module TestFirst {
result = _(list).first<TResult>();
}
result = <number[]>_.take([1, 2, 3]);
result = <number[]>_.take([1, 2, 3], 2);
result = <number[]>_.takeWhile([1, 2, 3], (num) => num < 3);
result = <boolean[]>_.takeWhile(foodsOrganic, 'organic');
result = <IFoodType[]>_.takeWhile(foodsType, { 'type': 'fruit' });
result = <number[]>_([1, 2, 3]).take().value();
result = <number[]>_([1, 2, 3]).take(2).value();
result = <number[]>_([1, 2, 3]).takeWhile(function (num) {
return num < 3;
}).value();
@@ -456,6 +452,21 @@ result = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function
return this.wordToNumber[word];
}, sortedIndexDict);
// _.take
module TestTake {
let array: TResult[];
let list: _.List<TResult>;
let result: TResult[];
result = _.take<TResult>(array);
result = _.take<TResult>(array, 42);
result = _.take<TResult>(list);
result = _.take<TResult>(list, 42);
result = _(array).take().value();
result = _(array).take(42).value();
result = _(list).take<TResult>().value();
result = _(list).take<TResult>(42).value();
}
// _.takeRight
{
let testTakeRightArray: TResult[];
+29 -35
View File
@@ -587,30 +587,6 @@ declare module _ {
}
interface LoDashStatic {
/**
* @see _.first
**/
take<T>(array: Array<T>): T[];
/**
* @see _.first
**/
take<T>(array: List<T>): T[];
/**
* @see _.first
**/
take<T>(
array: Array<T>,
n: number): T[];
/**
* @see _.first
**/
take<T>(
array: List<T>,
n: number): T[];
/**
* Takes the first items from an array or list based on a predicate
* @param array The array or list of items on which the result set will be based
@@ -645,17 +621,6 @@ declare module _ {
}
interface LoDashArrayWrapper<T> {
/**
* @see _.first
**/
take(): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param n The number of elements to return.
**/
take(n: number): LoDashArrayWrapper<T>;
/**
* Takes the first items based on a predicate
* @param predicate The function called per element.
@@ -1284,6 +1249,35 @@ declare module _ {
whereValue: W): number;
}
//_.take
interface LoDashStatic {
/**
* Creates a slice of array with n elements taken from the beginning.
*
* @param array The array to query.
* @param n The number of elements to take.
* @return Returns the slice of array.
*/
take<T>(
array: List<T>,
n?: number
): T[];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.take
*/
take(n?: number): LoDashArrayWrapper<T>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.take
*/
take<TResult>(n?: number): LoDashArrayWrapper<TResult>;
}
//_.takeRight
interface LoDashStatic {
/**