From af73a334c85d6dcd18eef5397f42904a7e0854d0 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Tue, 22 Sep 2015 04:26:45 +0500 Subject: [PATCH] lodash: changed _.rest() method (alias _.tail()) --- lodash/lodash-tests.ts | 36 +++++--- lodash/lodash.d.ts | 183 +++++++++-------------------------------- 2 files changed, 63 insertions(+), 156 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index db15ebc4a..3f2cb04f6 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -276,18 +276,6 @@ module TestDropWhile { result = _(list).dropWhile<{a: number;}, TResult>({a: 42}).value(); } -result = _.rest([1, 2, 3]); -result = _.rest([1, 2, 3], 2); -result = _.rest([1, 2, 3], (num) => num < 3) -result = _.rest(foodsOrganic, 'test'); -result = _.rest(foodsType, { 'type': 'value' }); - -result = _.tail([1, 2, 3]) -result = _.tail([1, 2, 3], 2) -result = _.tail([1, 2, 3], (num) => num < 3) -result = _.tail(foodsOrganic, 'test') -result = _.tail(foodsType, { 'type': 'value' }) - // _.fill var testFillArray = [1, 2, 3]; var testFillList: _.List = {0: 1, 1: 2, 2: 3, length: 3}; @@ -584,6 +572,18 @@ module TestRemove { result = _(list).remove<{a: number}, TResult>({a: 42}).value(); } +// _.rest +module TestRest { + let array: TResult[]; + let list: _.List; + let result: TResult[]; + + result = _.rest(array); + result = _.rest(list); + result = _(array).rest().value(); + result = _(list).rest().value(); +} + // _.slice { let testSliceArray: TResult[]; @@ -608,6 +608,18 @@ result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function return this.wordToNumber[word]; }, sortedIndexDict); +// _.tail +module TestTail { + let array: TResult[]; + let list: _.List; + let result: TResult[]; + + result = _.tail(array); + result = _.tail(list); + result = _(array).tail().value(); + result = _(list).tail().value(); +} + // _.take module TestTake { let array: TResult[]; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 5a3e0df9e..d8282d954 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1165,155 +1165,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(array: Array): 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(array: List): T[]; + } + interface LoDashArrayWrapper { /** - * @see _.rest - **/ - rest( - array: Array, - callback: ListIterator, - thisArg?: any): T[]; + * @see _.rest + */ + rest(): LoDashArrayWrapper; + } + interface LoDashObjectWrapper { /** - * @see _.rest - **/ - rest( - array: List, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.rest - **/ - rest( - array: Array, - n: number): T[]; - - /** - * @see _.rest - **/ - rest( - array: List, - n: number): T[]; - - /** - * @see _.rest - **/ - rest( - array: Array, - pluckValue: string): T[]; - - /** - * @see _.rest - **/ - rest( - array: List, - pluckValue: string): T[]; - - /** - * @see _.rest - **/ - rest( - array: Array, - whereValue: W): T[]; - - /** - * @see _.rest - **/ - rest( - array: List, - whereValue: W): T[]; - - /** - * @see _.rest - **/ - tail(array: Array): T[]; - - /** - * @see _.rest - **/ - tail(array: List): T[]; - - /** - * @see _.rest - **/ - tail( - array: Array, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.rest - **/ - tail( - array: List, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.rest - **/ - tail( - array: Array, - n: number): T[]; - - /** - * @see _.rest - **/ - tail( - array: List, - n: number): T[]; - - /** - * @see _.rest - **/ - tail( - array: Array, - pluckValue: string): T[]; - - /** - * @see _.rest - **/ - tail( - array: List, - pluckValue: string): T[]; - - /** - * @see _.rest - **/ - tail( - array: Array, - whereValue: W): T[]; - - /** - * @see _.rest - **/ - tail( - array: List, - whereValue: W): T[]; + * @see _.rest + */ + rest(): LoDashArrayWrapper; } //_.slice @@ -1413,6 +1286,28 @@ declare module _ { whereValue: W): number; } + //_.tail + interface LoDashStatic { + /** + * @see _.rest + */ + tail(array: List): T[]; + } + + interface LoDashArrayWrapper { + /** + * @see _.rest + */ + tail(): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.rest + */ + tail(): LoDashArrayWrapper; + } + //_.take interface LoDashStatic { /**