From 2162519f36fb92efda7641788fb8e34fd9029be9 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Wed, 2 Dec 2015 23:05:34 +0500 Subject: [PATCH] lodash: signatures of _.sortedLastIndex have been changed --- lodash/lodash-tests.ts | 91 +++++++++++++-- lodash/lodash.d.ts | 249 +++++++++++++++++++++++++++++++++-------- 2 files changed, 280 insertions(+), 60 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 9cae2a8721..b64751cf41 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1315,17 +1315,86 @@ module TestSortedIndex { // _.sortedLastIndex module TestSortedLastIndex { - result = _.sortedLastIndex([20, 30, 50], 40); - result = _.sortedLastIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); - var sortedLastIndexDict: { wordToNumber: { [idx: string]: number } } = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } - }; - result = _.sortedLastIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { - return sortedLastIndexDict.wordToNumber[word]; - }); - result = _.sortedLastIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { - return this.wordToNumber[word]; - }, sortedLastIndexDict); + type SampleType = {a: number; b: string; c: boolean;}; + + let array: SampleType[]; + let list: _.List; + + let value: SampleType; + + let stringIterator: (x: string) => number; + let arrayIterator: (x: SampleType) => number; + let listIterator: (x: SampleType) => number; + + { + let result: number; + + result = _.sortedLastIndex('', ''); + result = _.sortedLastIndex('', '', stringIterator); + result = _.sortedLastIndex('', '', stringIterator, any); + result = _.sortedLastIndex('', '', stringIterator); + result = _.sortedLastIndex('', '', stringIterator, any); + + result = _.sortedLastIndex(array, value); + result = _.sortedLastIndex(array, value, arrayIterator); + result = _.sortedLastIndex(array, value, arrayIterator, any); + result = _.sortedLastIndex(array, value, ''); + result = _.sortedLastIndex(array, value, {a: 42}); + result = _.sortedLastIndex(array, value, arrayIterator); + result = _.sortedLastIndex(array, value, arrayIterator, any); + result = _.sortedLastIndex<{a: number}, SampleType>(array, value, {a: 42}); + + result = _.sortedLastIndex(list, value); + result = _.sortedLastIndex(list, value, listIterator); + result = _.sortedLastIndex(list, value, listIterator, any); + result = _.sortedLastIndex(list, value, ''); + result = _.sortedLastIndex(list, value, {a: 42}); + result = _.sortedLastIndex(list, value, listIterator); + result = _.sortedLastIndex(list, value, listIterator, any); + result = _.sortedLastIndex<{a: number}, SampleType>(list, value, {a: 42}); + + result = _('').sortedLastIndex(''); + result = _('').sortedLastIndex('', stringIterator); + result = _('').sortedLastIndex('', stringIterator, any); + + result = _(array).sortedLastIndex(value); + result = _(array).sortedLastIndex(value, arrayIterator); + result = _(array).sortedLastIndex(value, arrayIterator, any); + result = _(array).sortedLastIndex(value, ''); + result = _(array).sortedLastIndex<{a: number}>(value, {a: 42}); + + result = _(list).sortedLastIndex(value); + result = _(list).sortedLastIndex(value, listIterator); + result = _(list).sortedLastIndex(value, listIterator, any); + result = _(list).sortedLastIndex(value, ''); + result = _(list).sortedLastIndex(value, {a: 42}); + result = _(list).sortedLastIndex(value, listIterator); + result = _(list).sortedLastIndex(value, listIterator, any); + result = _(list).sortedLastIndex<{a: number}, SampleType>(value, {a: 42}); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('').chain().sortedLastIndex(''); + result = _('').chain().sortedLastIndex('', stringIterator); + result = _('').chain().sortedLastIndex('', stringIterator, any); + + result = _(array).chain().sortedLastIndex(value); + result = _(array).chain().sortedLastIndex(value, arrayIterator); + result = _(array).chain().sortedLastIndex(value, arrayIterator, any); + result = _(array).chain().sortedLastIndex(value, ''); + result = _(array).chain().sortedLastIndex<{a: number}>(value, {a: 42}); + + result = _(list).chain().sortedLastIndex(value); + result = _(list).chain().sortedLastIndex(value, listIterator); + result = _(list).chain().sortedLastIndex(value, listIterator, any); + result = _(list).chain().sortedLastIndex(value, ''); + result = _(list).chain().sortedLastIndex(value, {a: 42}); + result = _(list).chain().sortedLastIndex(value, listIterator); + result = _(list).chain().sortedLastIndex(value, listIterator, any); + result = _(list).chain().sortedLastIndex<{a: number}, SampleType>(value, {a: 42}); + } } // _.tail diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index ed8d72443a..a8d6e5736b 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2156,71 +2156,222 @@ declare module _ { //_.sortedLastIndex interface LoDashStatic { /** - * Uses a binary search to determine the highest index at which a value should be inserted - * into a given sorted array in order to maintain the sort order of the array. If a callback - * is provided it will be executed for value and each element of array to compute their sort - * ranking. The callback is bound to thisArg and invoked with one argument; (value). - * - * 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 sorted list. - * @param value The value to determine its index within `list`. - * @param callback Iterator to compute the sort ranking of each value, optional. - * @return The index at which value should be inserted into array. - **/ - sortedLastIndex( - array: Array, - value: T, - callback?: (x: T) => TSort, - thisArg?: any): number; - - /** - * @see _.sortedLastIndex - **/ + * This method is like _.sortedIndex except that it returns the highest index at which value should be + * inserted into array in order to maintain its sort order. + * + * @param array The sorted array to inspect. + * @param value The value to evaluate. + * @param iteratee The function invoked per iteration. + * @param thisArg The this binding of iteratee. + * @return Returns the index at which value should be inserted into array. + */ sortedLastIndex( array: List, value: T, - callback?: (x: T) => TSort, - thisArg?: any): number; + iteratee?: (x: T) => TSort, + thisArg?: any + ): number; /** - * @see _.sortedLastIndex - * @param pluckValue the _.pluck style callback - **/ - sortedLastIndex( - array: Array, - value: T, - pluckValue: string): number; - - /** - * @see _.sortedLastIndex - * @param pluckValue the _.pluck style callback - **/ + * @see _.sortedLastIndex + */ sortedLastIndex( array: List, value: T, - pluckValue: string): number; + iteratee?: (x: T) => any, + thisArg?: any + ): number; /** - * @see _.sortedLastIndex - * @param pluckValue the _.where style callback - **/ - sortedLastIndex( - array: Array, + * @see _.sortedLastIndex + */ + sortedLastIndex( + array: List, value: T, - whereValue: W): number; + iteratee: string + ): number; /** - * @see _.sortedLastIndex - * @param pluckValue the _.where style callback - **/ + * @see _.sortedLastIndex + */ sortedLastIndex( array: List, value: T, - whereValue: W): number; + iteratee: W + ): number; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + array: List, + value: T, + iteratee: Object + ): number; + } + + interface LoDashImplicitWrapper { + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: string, + iteratee?: (x: string) => TSort, + thisArg?: any + ): number; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): number; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: string + ): number; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: W + ): number; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): number; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee?: (x: T) => any, + thisArg?: any + ): number; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: string + ): number; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: W + ): number; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: Object + ): number; + } + + interface LoDashExplicitWrapper { + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: string, + iteratee?: (x: string) => TSort, + thisArg?: any + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: string + ): LoDashExplicitWrapper; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: W + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee?: (x: T) => any, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: string + ): LoDashExplicitWrapper; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: W + ): LoDashExplicitWrapper; + + /** + * @see _.sortedLastIndex + */ + sortedLastIndex( + value: T, + iteratee: Object + ): LoDashExplicitWrapper; } //_.tail