From c59dcb8d6f88e858ceb6dd72dd1a0325dc580d47 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Mon, 30 Nov 2015 09:48:26 +0500 Subject: [PATCH] lodash: signatures of _.sortedIndex have been changed --- lodash/lodash-tests.ts | 91 +++++++++++++-- lodash/lodash.d.ts | 253 +++++++++++++++++++++++++++++++++-------- 2 files changed, 284 insertions(+), 60 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index bdc08ccdc7..d48362b626 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1164,17 +1164,86 @@ module TestSlice { // _.sortedIndex module TestSortedIndex { - result = _.sortedIndex([20, 30, 50], 40); - result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); - var sortedIndexDict: { wordToNumber: { [idx: string]: number } } = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } - }; - result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { - return sortedIndexDict.wordToNumber[word]; - }); - result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) { - return this.wordToNumber[word]; - }, sortedIndexDict); + 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 = _.sortedIndex('', ''); + result = _.sortedIndex('', '', stringIterator); + result = _.sortedIndex('', '', stringIterator, any); + result = _.sortedIndex('', '', stringIterator); + result = _.sortedIndex('', '', stringIterator, any); + + result = _.sortedIndex(array, value); + result = _.sortedIndex(array, value, arrayIterator); + result = _.sortedIndex(array, value, arrayIterator, any); + result = _.sortedIndex(array, value, ''); + result = _.sortedIndex(array, value, {a: 42}); + result = _.sortedIndex(array, value, arrayIterator); + result = _.sortedIndex(array, value, arrayIterator, any); + result = _.sortedIndex<{a: number}, SampleType>(array, value, {a: 42}); + + result = _.sortedIndex(list, value); + result = _.sortedIndex(list, value, listIterator); + result = _.sortedIndex(list, value, listIterator, any); + result = _.sortedIndex(list, value, ''); + result = _.sortedIndex(list, value, {a: 42}); + result = _.sortedIndex(list, value, listIterator); + result = _.sortedIndex(list, value, listIterator, any); + result = _.sortedIndex<{a: number}, SampleType>(list, value, {a: 42}); + + result = _('').sortedIndex(''); + result = _('').sortedIndex('', stringIterator); + result = _('').sortedIndex('', stringIterator, any); + + result = _(array).sortedIndex(value); + result = _(array).sortedIndex(value, arrayIterator); + result = _(array).sortedIndex(value, arrayIterator, any); + result = _(array).sortedIndex(value, ''); + result = _(array).sortedIndex<{a: number}>(value, {a: 42}); + + result = _(list).sortedIndex(value); + result = _(list).sortedIndex(value, listIterator); + result = _(list).sortedIndex(value, listIterator, any); + result = _(list).sortedIndex(value, ''); + result = _(list).sortedIndex(value, {a: 42}); + result = _(list).sortedIndex(value, listIterator); + result = _(list).sortedIndex(value, listIterator, any); + result = _(list).sortedIndex<{a: number}, SampleType>(value, {a: 42}); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('').chain().sortedIndex(''); + result = _('').chain().sortedIndex('', stringIterator); + result = _('').chain().sortedIndex('', stringIterator, any); + + result = _(array).chain().sortedIndex(value); + result = _(array).chain().sortedIndex(value, arrayIterator); + result = _(array).chain().sortedIndex(value, arrayIterator, any); + result = _(array).chain().sortedIndex(value, ''); + result = _(array).chain().sortedIndex<{a: number}>(value, {a: 42}); + + result = _(list).chain().sortedIndex(value); + result = _(list).chain().sortedIndex(value, listIterator); + result = _(list).chain().sortedIndex(value, listIterator, any); + result = _(list).chain().sortedIndex(value, ''); + result = _(list).chain().sortedIndex(value, {a: 42}); + result = _(list).chain().sortedIndex(value, listIterator); + result = _(list).chain().sortedIndex(value, listIterator, any); + result = _(list).chain().sortedIndex<{a: number}, SampleType>(value, {a: 42}); + } } // _.sortedLastIndex diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index ad465c5c39..5af03703ad 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1842,71 +1842,226 @@ declare module _ { //_.sortedIndex interface LoDashStatic { /** - * Uses a binary search to determine the smallest 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. - **/ - sortedIndex( - array: Array, - value: T, - callback?: (x: T) => TSort, - thisArg?: any): number; - - /** - * @see _.sortedIndex - **/ + * Uses a binary search to determine the lowest index at which value should be inserted into array in order to maintain its sort order. If an iteratee function is provided it’s invoked for value and each element of array to compute their sort ranking. The iteratee is bound to thisArg and invoked with one argument; (value). + * + * If a property name is provided for iteratee the created _.property style callback returns the property value of the given element. + * + * If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false. + * + * If an object is provided for iteratee the created _.matches style callback returns true for elements that have the properties of the given object, else false. + * + * @param array The sorted array to inspect. + * @param value The value to evaluate. + * @param iteratee The function invoked per iteration. + * @return The this binding of iteratee. + */ sortedIndex( array: List, value: T, - callback?: (x: T) => TSort, - thisArg?: any): number; + iteratee?: (x: T) => TSort, + thisArg?: any + ): number; /** - * @see _.sortedIndex - * @param pluckValue the _.pluck style callback - **/ - sortedIndex( - array: Array, - value: T, - pluckValue: string): number; - - /** - * @see _.sortedIndex - * @param pluckValue the _.pluck style callback - **/ + * @see _.sortedIndex + */ sortedIndex( array: List, value: T, - pluckValue: string): number; + iteratee?: (x: T) => any, + thisArg?: any + ): number; /** - * @see _.sortedIndex - * @param pluckValue the _.where style callback - **/ - sortedIndex( - array: Array, + * @see _.sortedIndex + */ + sortedIndex( + array: List, value: T, - whereValue: W): number; + iteratee: string + ): number; /** - * @see _.sortedIndex - * @param pluckValue the _.where style callback - **/ + * @see _.sortedIndex + */ sortedIndex( array: List, value: T, - whereValue: W): number; + iteratee: W + ): number; + + /** + * @see _.sortedIndex + */ + sortedIndex( + array: List, + value: T, + iteratee: Object + ): number; + } + + interface LoDashImplicitWrapper { + /** + * @see _.sortedIndex + */ + sortedIndex( + value: string, + iteratee?: (x: string) => TSort, + thisArg?: any + ): number; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): number; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: string + ): number; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: W + ): number; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): number; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee?: (x: T) => any, + thisArg?: any + ): number; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: string + ): number; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: W + ): number; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: Object + ): number; + } + + interface LoDashExplicitWrapper { + /** + * @see _.sortedIndex + */ + sortedIndex( + value: string, + iteratee?: (x: string) => TSort, + thisArg?: any + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: string + ): LoDashExplicitWrapper; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: W + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee?: (x: T) => TSort, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee?: (x: T) => any, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: string + ): LoDashExplicitWrapper; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: W + ): LoDashExplicitWrapper; + + /** + * @see _.sortedIndex + */ + sortedIndex( + value: T, + iteratee: Object + ): LoDashExplicitWrapper; } //_.sortedLastIndex