From fd3b5297fa949a9920d8207febebf33effabd59c Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 14 Nov 2015 18:10:58 +0500 Subject: [PATCH] lodash: signatures of the method _.filter have been changed --- lodash/lodash-tests.ts | 205 +++++++++++++++-- lodash/lodash.d.ts | 498 +++++++++++++++++++++++++---------------- 2 files changed, 495 insertions(+), 208 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 4c587b57b..68b9da5eb 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -2745,22 +2745,103 @@ module TestEvery { } } -result = _.filter([1, 2, 3, 4, 5, 6]); -result = _.filter([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); -result = _.filter(foodsCombined, 'organic'); -result = _.filter(foodsCombined, { 'type': 'fruit' }); +// _.filter +module TestFilter { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; -result = _([1, 2, 3, 4, 5, 6]).filter(function (num) { return num % 2 == 0; }).value(); -result = _(foodsCombined).filter('organic').value(); -result = _(foodsCombined).filter({ 'type': 'fruit' }).value(); + let stringIterator: (char: string, index: number, string: string) => any; + let listIterator: (value: TResult, index: number, collection: _.List) => any; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => any; -result = _.select([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); -result = _.select(foodsCombined, 'organic'); -result = _.select(foodsCombined, { 'type': 'fruit' }); + { + let result: string[]; -result = _([1, 2, 3, 4, 5, 6]).select(function (num) { return num % 2 == 0; }).value(); -result = _(foodsCombined).select('organic').value(); -result = _(foodsCombined).select({ 'type': 'fruit' }).value(); + result = _.filter('', stringIterator); + result = _.filter('', stringIterator, any); + } + + { + let result: TResult[]; + + result = _.filter(array, listIterator); + result = _.filter(array, listIterator, any); + result = _.filter(array, ''); + result = _.filter(array, '', any); + result = _.filter<{a: number}, TResult>(array, {a: 42}); + + result = _.filter(list, listIterator); + result = _.filter(list, listIterator, any); + result = _.filter(list, ''); + result = _.filter(list, '', any); + result = _.filter<{a: number}, TResult>(list, {a: 42}); + + result = _.filter(dictionary, dictionaryIterator); + result = _.filter(dictionary, dictionaryIterator, any); + result = _.filter(dictionary, ''); + result = _.filter(dictionary, '', any); + result = _.filter<{a: number}, TResult>(dictionary, {a: 42}); + } + + { + let result: _.LoDashImplicitArrayWrapper; + + result = _('').filter(stringIterator); + result = _('').filter(stringIterator, any); + } + + { + let result: _.LoDashImplicitArrayWrapper; + + result = _(array).filter(listIterator); + result = _(array).filter(listIterator, any); + result = _(array).filter(''); + result = _(array).filter('', any); + result = _(array).filter<{a: number}>({a: 42}); + + result = _(list).filter(listIterator); + result = _(list).filter(listIterator, any); + result = _(list).filter(''); + result = _(list).filter('', any); + result = _(list).filter<{a: number}, TResult>({a: 42}); + + result = _(dictionary).filter(dictionaryIterator); + result = _(dictionary).filter(dictionaryIterator, any); + result = _(dictionary).filter(''); + result = _(dictionary).filter('', any); + result = _(dictionary).filter<{a: number}, TResult>({a: 42}); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _('').chain().filter(stringIterator); + result = _('').chain().filter(stringIterator, any); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _(array).chain().filter(listIterator); + result = _(array).chain().filter(listIterator, any); + result = _(array).chain().filter(''); + result = _(array).chain().filter('', any); + result = _(array).chain().filter<{a: number}>({a: 42}); + + result = _(list).chain().filter(listIterator); + result = _(list).chain().filter(listIterator, any); + result = _(list).chain().filter(''); + result = _(list).chain().filter('', any); + result = _(list).chain().filter<{a: number}, TResult>({a: 42}); + + result = _(dictionary).chain().filter(dictionaryIterator); + result = _(dictionary).chain().filter(dictionaryIterator, any); + result = _(dictionary).chain().filter(''); + result = _(dictionary).chain().filter('', any); + result = _(dictionary).chain().filter<{a: number}, TResult>({a: 42}); + } +} // _.find module TestFind { @@ -3296,6 +3377,104 @@ result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).sample(2); result = _([1, 2, 3, 4]).sample().value(); result = _([1, 2, 3, 4]).sample(2).value(); +// _.select +module TestSelect { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; + + let stringIterator: (char: string, index: number, string: string) => any; + let listIterator: (value: TResult, index: number, collection: _.List) => any; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => any; + + { + let result: string[]; + + result = _.select('', stringIterator); + result = _.select('', stringIterator, any); + } + + { + let result: TResult[]; + + result = _.select(array, listIterator); + result = _.select(array, listIterator, any); + result = _.select(array, ''); + result = _.select(array, '', any); + result = _.select<{a: number}, TResult>(array, {a: 42}); + + result = _.select(list, listIterator); + result = _.select(list, listIterator, any); + result = _.select(list, ''); + result = _.select(list, '', any); + result = _.select<{a: number}, TResult>(list, {a: 42}); + + result = _.select(dictionary, dictionaryIterator); + result = _.select(dictionary, dictionaryIterator, any); + result = _.select(dictionary, ''); + result = _.select(dictionary, '', any); + result = _.select<{a: number}, TResult>(dictionary, {a: 42}); + } + + { + let result: _.LoDashImplicitArrayWrapper; + + result = _('').select(stringIterator); + result = _('').select(stringIterator, any); + } + + { + let result: _.LoDashImplicitArrayWrapper; + + result = _(array).select(listIterator); + result = _(array).select(listIterator, any); + result = _(array).select(''); + result = _(array).select('', any); + result = _(array).select<{a: number}>({a: 42}); + + result = _(list).select(listIterator); + result = _(list).select(listIterator, any); + result = _(list).select(''); + result = _(list).select('', any); + result = _(list).select<{a: number}, TResult>({a: 42}); + + result = _(dictionary).select(dictionaryIterator); + result = _(dictionary).select(dictionaryIterator, any); + result = _(dictionary).select(''); + result = _(dictionary).select('', any); + result = _(dictionary).select<{a: number}, TResult>({a: 42}); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _('').chain().select(stringIterator); + result = _('').chain().select(stringIterator, any); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _(array).chain().select(listIterator); + result = _(array).chain().select(listIterator, any); + result = _(array).chain().select(''); + result = _(array).chain().select('', any); + result = _(array).chain().select<{a: number}>({a: 42}); + + result = _(list).chain().select(listIterator); + result = _(list).chain().select(listIterator, any); + result = _(list).chain().select(''); + result = _(list).chain().select('', any); + result = _(list).chain().select<{a: number}, TResult>({a: 42}); + + result = _(dictionary).chain().select(dictionaryIterator); + result = _(dictionary).chain().select(dictionaryIterator, any); + result = _(dictionary).chain().select(''); + result = _(dictionary).chain().select('', any); + result = _(dictionary).chain().select<{a: number}, TResult>({a: 42}); + } +} + // _.shuffle module TestShuffle { let array: TResult[]; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 98d8bf55d..85f7247f8 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -4507,228 +4507,177 @@ declare module _ { //_.filter interface LoDashStatic { /** - * Iterates over elements of a collection, returning an array of all elements the - * identity function returns truey for. - * - * @param collection The collection to iterate over. - * @return Returns a new array of elements that passed the callback check. - **/ - filter( - collection: (Array|List)): T[]; - - /** - * Iterates over elements of a collection, returning an array of all elements the - * callback returns truey for. The callback is bound to thisArg and invoked with three - * arguments; (value, index|key, collection). - * - * 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 collection The collection to iterate over. - * @param callback The function called per iteration. - * @param context The this binding of callback. - * @return Returns a new array of elements that passed the callback check. - **/ - filter( - collection: Array, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.filter - **/ + * Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The + * predicate is bound to thisArg and invoked with three arguments: (value, index|key, collection). + * + * If a property name is provided for predicate 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 predicate the created _.matches style callback returns true for elements that + * have the properties of the given object, else false. + * + * @alias _.select + * + * @param collection The collection to iterate over. + * @param predicate The function invoked per iteration. + * @param thisArg The this binding of predicate. + * @return Returns the new filtered array. + */ filter( collection: List, - callback: ListIterator, - thisArg?: any): T[]; + predicate?: ListIterator, + thisArg?: any + ): T[]; /** - * @see _.filter - **/ + * @see _.filter + */ filter( collection: Dictionary, - callback: DictionaryIterator, - thisArg?: any): T[]; + predicate?: DictionaryIterator, + thisArg?: any + ): T[]; /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ + * @see _.filter + */ + filter( + collection: string, + predicate?: StringIterator, + thisArg?: any + ): string[]; + + /** + * @see _.filter + */ filter( - collection: Array, - pluckValue: string): T[]; + collection: List|Dictionary, + predicate: string, + thisArg?: any + ): T[]; /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - filter( - collection: List, - pluckValue: string): T[]; + * @see _.filter + */ + filter( + collection: List|Dictionary, + predicate: W + ): T[]; + } + interface LoDashImplicitWrapper { /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - filter( - collection: Dictionary, - pluckValue: string): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - filter( - collection: Array, - whereValue: W): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - filter( - collection: List, - whereValue: W): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - filter( - collection: Dictionary, - whereValue: W): T[]; - - /** - * @see _.filter - **/ - select( - collection: Array, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.filter - **/ - select( - collection: List, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.filter - **/ - select( - collection: Dictionary, - callback: DictionaryIterator, - thisArg?: any): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: Array, - pluckValue: string): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: List, - pluckValue: string): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: Dictionary, - pluckValue: string): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: Array, - whereValue: W): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: List, - whereValue: W): T[]; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: Dictionary, - whereValue: W): T[]; + * @see _.filter + */ + filter( + predicate?: StringIterator, + thisArg?: any + ): LoDashImplicitArrayWrapper; } interface LoDashImplicitArrayWrapper { /** - * @see _.filter - **/ - filter(): LoDashImplicitArrayWrapper; - - /** - * @see _.filter - **/ + * @see _.filter + */ filter( - callback: ListIterator, - thisArg?: any): LoDashImplicitArrayWrapper; + predicate: ListIterator, + thisArg?: any + ): LoDashImplicitArrayWrapper; /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ + * @see _.filter + */ filter( - pluckValue: string): LoDashImplicitArrayWrapper; + predicate: string, + thisArg?: any + ): LoDashImplicitArrayWrapper; /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - filter( - whereValue: W): LoDashImplicitArrayWrapper; - - /** - * @see _.filter - **/ - select( - callback: ListIterator, - thisArg?: any): LoDashImplicitArrayWrapper; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - pluckValue: string): LoDashImplicitArrayWrapper; - - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - whereValue: W): LoDashImplicitArrayWrapper; + * @see _.filter + */ + filter(predicate: W): LoDashImplicitArrayWrapper; } interface LoDashImplicitObjectWrapper { /** - * @see _.filter - **/ - filter( - callback: ObjectIterator, - thisArg?: any): LoDashImplicitObjectWrapper; + * @see _.filter + */ + filter( + predicate: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashImplicitArrayWrapper; + + /** + * @see _.filter + */ + filter( + predicate: string, + thisArg?: any + ): LoDashImplicitArrayWrapper; + + /** + * @see _.filter + */ + filter(predicate: W): LoDashImplicitArrayWrapper; + } + + interface LoDashExplicitWrapper { + /** + * @see _.filter + */ + filter( + predicate?: StringIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.filter + */ + filter( + predicate: ListIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + filter( + predicate: string, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + filter(predicate: W): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.filter + */ + filter( + predicate: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + filter( + predicate: string, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + filter(predicate: W): LoDashExplicitArrayWrapper; } //_.find @@ -6362,6 +6311,165 @@ declare module _ { sample(): LoDashImplicitWrapper; } + //_.select + interface LoDashStatic { + /** + * @see _.filter + */ + select( + collection: List, + predicate?: ListIterator, + thisArg?: any + ): T[]; + + /** + * @see _.filter + */ + select( + collection: Dictionary, + predicate?: DictionaryIterator, + thisArg?: any + ): T[]; + + /** + * @see _.filter + */ + select( + collection: string, + predicate?: StringIterator, + thisArg?: any + ): string[]; + + /** + * @see _.filter + */ + select( + collection: List|Dictionary, + predicate: string, + thisArg?: any + ): T[]; + + /** + * @see _.filter + */ + select( + collection: List|Dictionary, + predicate: W + ): T[]; + } + + interface LoDashImplicitWrapper { + /** + * @see _.filter + */ + select( + predicate?: StringIterator, + thisArg?: any + ): LoDashImplicitArrayWrapper; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.filter + */ + select( + predicate: ListIterator, + thisArg?: any + ): LoDashImplicitArrayWrapper; + + /** + * @see _.filter + */ + select( + predicate: string, + thisArg?: any + ): LoDashImplicitArrayWrapper; + + /** + * @see _.filter + */ + select(predicate: W): LoDashImplicitArrayWrapper; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.filter + */ + select( + predicate: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashImplicitArrayWrapper; + + /** + * @see _.filter + */ + select( + predicate: string, + thisArg?: any + ): LoDashImplicitArrayWrapper; + + /** + * @see _.filter + */ + select(predicate: W): LoDashImplicitArrayWrapper; + } + + interface LoDashExplicitWrapper { + /** + * @see _.filter + */ + select( + predicate?: StringIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.filter + */ + select( + predicate: ListIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + select( + predicate: string, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + select(predicate: W): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.filter + */ + select( + predicate: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + select( + predicate: string, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.filter + */ + select(predicate: W): LoDashExplicitArrayWrapper; + } + //_.shuffle interface LoDashStatic { /**