Merge pull request #5942 from chrootsu/lodash-rest

lodash: changed _.rest() method (alias _.tail())
This commit is contained in:
Masahiro Wakame
2015-10-13 00:23:45 +09:00
2 changed files with 63 additions and 156 deletions
+24 -12
View File
@@ -312,18 +312,6 @@ module TestDropWhile {
result = _(list).dropWhile<{a: number;}, TResult>({a: 42}).value();
}
result = <number[]>_.rest([1, 2, 3]);
result = <number[]>_.rest([1, 2, 3], 2);
result = <number[]>_.rest([1, 2, 3], (num) => num < 3)
result = <IFoodOrganic[]>_.rest(foodsOrganic, 'test');
result = <IFoodType[]>_.rest(foodsType, { 'type': 'value' });
result = <number[]>_.tail([1, 2, 3])
result = <number[]>_.tail([1, 2, 3], 2)
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};
@@ -620,6 +608,18 @@ module TestRemove {
result = _(list).remove<{a: number}, TResult>({a: 42}).value();
}
// _.rest
module TestRest {
let array: TResult[];
let list: _.List<TResult>;
let result: TResult[];
result = _.rest<TResult>(array);
result = _.rest<TResult>(list);
result = _(array).rest().value();
result = _(list).rest<TResult>().value();
}
// _.slice
{
let testSliceArray: TResult[];
@@ -644,6 +644,18 @@ result = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function
return this.wordToNumber[word];
}, sortedIndexDict);
// _.tail
module TestTail {
let array: TResult[];
let list: _.List<TResult>;
let result: TResult[];
result = _.tail<TResult>(array);
result = _.tail<TResult>(list);
result = _(array).tail().value();
result = _(list).tail<TResult>().value();
}
// _.take
module TestTake {
let array: TResult[];
+39 -144
View File
@@ -1259,155 +1259,28 @@ declare module _ {
//_.rest
interface LoDashStatic {
/**
* The opposite of _.initial this method gets all but the first element or first n elements of
* an array. If a callback function is provided elements at the beginning of the array are excluded
* from the result as long as the callback returns truey. The callback is bound to thisArg and
* invoked with three arguments; (value, index, array).
*
* If a property name is provided for callback the created "_.pluck" style callback will return
* the property value of the given element.
*
* If an object is provided for callback the created "_.where" style callback will return true
* for elements that have the properties of the given object, else false.
* @param array The array to query.
* @param {(Function|Object|number|string)} [callback=1] The function called per element or the number
* of elements to exclude. If a property name or object is provided it will be used to create a
* ".pluck" or ".where" style callback, respectively.
* @param {*} [thisArg] The this binding of callback.
* @return Returns a slice of array.
**/
rest<T>(array: Array<T>): T[];
/**
* @see _.rest
**/
* Gets all but the first element of array.
*
* @alias _.tail
*
* @param array The array to query.
* @return Returns the slice of array.
*/
rest<T>(array: List<T>): T[];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.rest
**/
rest<T>(
array: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
* @see _.rest
*/
rest(): LoDashArrayWrapper<T>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.rest
**/
rest<T>(
array: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.rest
**/
rest<T>(
array: Array<T>,
n: number): T[];
/**
* @see _.rest
**/
rest<T>(
array: List<T>,
n: number): T[];
/**
* @see _.rest
**/
rest<T>(
array: Array<T>,
pluckValue: string): T[];
/**
* @see _.rest
**/
rest<T>(
array: List<T>,
pluckValue: string): T[];
/**
* @see _.rest
**/
rest<W, T>(
array: Array<T>,
whereValue: W): T[];
/**
* @see _.rest
**/
rest<W, T>(
array: List<T>,
whereValue: W): T[];
/**
* @see _.rest
**/
tail<T>(array: Array<T>): T[];
/**
* @see _.rest
**/
tail<T>(array: List<T>): T[];
/**
* @see _.rest
**/
tail<T>(
array: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.rest
**/
tail<T>(
array: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.rest
**/
tail<T>(
array: Array<T>,
n: number): T[];
/**
* @see _.rest
**/
tail<T>(
array: List<T>,
n: number): T[];
/**
* @see _.rest
**/
tail<T>(
array: Array<T>,
pluckValue: string): T[];
/**
* @see _.rest
**/
tail<T>(
array: List<T>,
pluckValue: string): T[];
/**
* @see _.rest
**/
tail<W, T>(
array: Array<T>,
whereValue: W): T[];
/**
* @see _.rest
**/
tail<W, T>(
array: List<T>,
whereValue: W): T[];
* @see _.rest
*/
rest<TResult>(): LoDashArrayWrapper<TResult>;
}
//_.slice
@@ -1507,6 +1380,28 @@ declare module _ {
whereValue: W): number;
}
//_.tail
interface LoDashStatic {
/**
* @see _.rest
*/
tail<T>(array: List<T>): T[];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.rest
*/
tail(): LoDashArrayWrapper<T>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.rest
*/
tail<TResult>(): LoDashArrayWrapper<TResult>;
}
//_.take
interface LoDashStatic {
/**