diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index db15ebc4ab..fdf5b1b9a3 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1058,6 +1058,54 @@ result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return this.floor(num); }, Math); result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).countBy('length'); +// _.detect +module TestDetect { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; + + let listIterator: (value: TResult, index: number, collection: _.List) => boolean; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => boolean; + + let result: TResult; + + result = _.detect(array); + result = _.detect(array, listIterator); + result = _.detect(array, listIterator, any); + result = _.detect(array, ''); + result = _.detect<{a: number}, TResult>(array, {a: 42}); + + result = _.detect(list); + result = _.detect(list, listIterator); + result = _.detect(list, listIterator, any); + result = _.detect(list, ''); + result = _.detect<{a: number}, TResult>(list, {a: 42}); + + result = _.detect(dictionary); + result = _.detect(dictionary, dictionaryIterator); + result = _.detect(dictionary, dictionaryIterator, any); + result = _.detect(dictionary, ''); + result = _.detect<{a: number}, TResult>(dictionary, {a: 42}); + + result = _(array).detect(); + result = _(array).detect(listIterator); + result = _(array).detect(listIterator, any); + result = _(array).detect(''); + result = _(array).detect<{a: number}>({a: 42}); + + result = _(list).detect(); + result = _(list).detect(listIterator); + result = _(list).detect(listIterator, any); + result = _(list).detect(''); + result = _(list).detect<{a: number}, TResult>({a: 42}); + + result = _(dictionary).detect(); + result = _(dictionary).detect(dictionaryIterator); + result = _(dictionary).detect(dictionaryIterator, any); + result = _(dictionary).detect(''); + result = _(dictionary).detect<{a: number}, TResult>({a: 42}); +} + // _.every module TestEvery { let array: TResult[]; @@ -1123,20 +1171,53 @@ result = _([1, 2, 3, 4, 5, 6]).select(function (num) { return num % 2 result = _(foodsCombined).select('organic').value(); result = _(foodsCombined).select({ 'type': 'fruit' }).value(); -result = _.find([1, 2, 3, 4], num => num % 2 == 0); -result = _.find(foodsCombined, { 'type': 'vegetable' }); -result = _.find(foodsCombined, 'type', 'vegetable'); -result = _.find(foodsCombined, 'organic'); -result = _([1, 2, 3, 4]).find(num => num % 2 == 0); -result = _(foodsCombined).find({ 'type': 'vegetable' }); -result = _(foodsCombined).find('type', 'vegetable'); -result = _(foodsCombined).find('organic'); +// _.find +module TestFind { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; -result = _.detect([1, 2, 3, 4], function (num) { - return num % 2 == 0; -}); -result = _.detect(foodsCombined, { 'type': 'vegetable' }); -result = _.detect(foodsCombined, 'organic'); + let listIterator: (value: TResult, index: number, collection: _.List) => boolean; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => boolean; + + let result: TResult; + + result = _.find(array); + result = _.find(array, listIterator); + result = _.find(array, listIterator, any); + result = _.find(array, ''); + result = _.find<{a: number}, TResult>(array, {a: 42}); + + result = _.find(list); + result = _.find(list, listIterator); + result = _.find(list, listIterator, any); + result = _.find(list, ''); + result = _.find<{a: number}, TResult>(list, {a: 42}); + + result = _.find(dictionary); + result = _.find(dictionary, dictionaryIterator); + result = _.find(dictionary, dictionaryIterator, any); + result = _.find(dictionary, ''); + result = _.find<{a: number}, TResult>(dictionary, {a: 42}); + + result = _(array).find(); + result = _(array).find(listIterator); + result = _(array).find(listIterator, any); + result = _(array).find(''); + result = _(array).find<{a: number}>({a: 42}); + + result = _(list).find(); + result = _(list).find(listIterator); + result = _(list).find(listIterator, any); + result = _(list).find(''); + result = _(list).find<{a: number}, TResult>({a: 42}); + + result = _(dictionary).find(); + result = _(dictionary).find(dictionaryIterator); + result = _(dictionary).find(dictionaryIterator, any); + result = _(dictionary).find(''); + result = _(dictionary).find<{a: number}, TResult>({a: 42}); +} result = _.findWhere([1, 2, 3, 4], function (num) { return num % 2 == 0; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 5a3e0df9e9..412932d1e2 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2795,6 +2795,94 @@ declare module _ { thisArg?: any): LoDashObjectWrapper>; } + //_.detect + interface LoDashStatic { + /** + * @see _.find + */ + detect( + collection: List, + predicate?: ListIterator, + thisArg?: any + ): T; + + /** + * @see _.find + */ + detect( + collection: Dictionary, + predicate?: DictionaryIterator, + thisArg?: any + ): T; + + /** + * @see _.find + */ + detect( + collection: List|Dictionary, + predicate?: string, + thisArg?: any + ): T; + + /** + * @see _.find + */ + detect( + collection: List|Dictionary, + predicate?: TObject + ): T; + } + + interface LoDashArrayWrapper { + /** + * @see _.find + */ + detect( + predicate?: ListIterator, + thisArg?: any + ): T; + + /** + * @see _.find + */ + detect( + predicate?: string, + thisArg?: any + ): T; + + /** + * @see _.find + */ + detect( + predicate?: TObject + ): T; + } + + interface LoDashObjectWrapper { + /** + * @see _.find + */ + detect( + predicate?: ListIterator|DictionaryIterator, + thisArg?: any + ): TResult; + + /** + * @see _.find + */ + detect( + predicate?: string, + thisArg?: any + ): TResult; + + /** + * @see _.find + */ + detect( + predicate?: TObject + ): TResult; + } + //_.every interface LoDashStatic { /** @@ -3179,223 +3267,180 @@ declare module _ { //_.find interface LoDashStatic { /** - * Iterates over elements of collection, returning the first element 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. - * - * @param collection Searches for a value in this list. - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - * @return The found element, else undefined. - **/ - find( - collection: Array, - callback: ListIterator, - thisArg?: any): T; - - /** - * Alias of _.find - * @see _.find - **/ - detect( - collection: Array, - callback: ListIterator, - thisArg?: any): T; - - /** - * @see _.find - **/ + * Iterates over elements of collection, returning the first element 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 _.detect + * + * @param collection The collection to search. + * @param predicate The function invoked per iteration. + * @param thisArg The this binding of predicate. + * @return Returns the matched element, else undefined. + */ find( collection: List, - callback: ListIterator, - thisArg?: any): T; + predicate?: ListIterator, + thisArg?: any + ): T; /** - * Alias of _.find - * @see _.find - **/ - detect( - collection: List, - callback: ListIterator, - thisArg?: any): T; - - /** - * @see _.find - **/ + * @see _.find + */ find( collection: Dictionary, - callback: DictionaryIterator, - thisArg?: any): T; + predicate?: DictionaryIterator, + thisArg?: any + ): T; /** - * Alias of _.find - * @see _.find - **/ - detect( - collection: Dictionary, - callback: DictionaryIterator, - thisArg?: any): T; - - /** - * @see _.find - * @param _.matches style callback - **/ - find( - collection: Array|List|Dictionary, - whereValue: W): T; - - /** - * Alias of _.find - * @see _.find - * @param _.matches style callback - **/ - detect( - collection: Array|List|Dictionary, - whereValue: W): T; - - /** - * @see _.find - * @param _.matchesProperty style callback - **/ + * @see _.find + */ find( - collection: Array|List|Dictionary, - path: string, - srcValue: any): T; + collection: List|Dictionary, + predicate?: string, + thisArg?: any + ): T; /** - * Alias of _.find - * @see _.find - * @param _.matchesProperty style callback - **/ - detect( - collection: Array|List|Dictionary, - path: string, - srcValue: any): T; - - /** - * @see _.find - * @param _.property style callback - **/ - find( - collection: Array|List|Dictionary, - pluckValue: string): T; - - /** - * Alias of _.find - * @see _.find - * @param _.property style callback - **/ - detect( - collection: Array|List|Dictionary, - pluckValue: string): T; - - /** - * @see _.find - **/ - findWhere( - collection: Array, - callback: ListIterator, - thisArg?: any): T; - - /** - * @see _.find - **/ - findWhere( - collection: List, - callback: ListIterator, - thisArg?: any): T; - - /** - * @see _.find - **/ - findWhere( - collection: Dictionary, - callback: DictionaryIterator, - thisArg?: any): T; - - /** - * @see _.find - * @param _.matches style callback - **/ - findWhere( - collection: Array, - whereValue: W): T; - - /** - * @see _.find - * @param _.matches style callback - **/ - findWhere( - collection: List, - whereValue: W): T; - - /** - * @see _.find - * @param _.matches style callback - **/ - findWhere( - collection: Dictionary, - whereValue: W): T; - - /** - * @see _.find - * @param _.property style callback - **/ - findWhere( - collection: Array, - pluckValue: string): T; - - /** - * @see _.find - * @param _.property style callback - **/ - findWhere( - collection: List, - pluckValue: string): T; - - /** - * @see _.find - * @param _.property style callback - **/ - findWhere( - collection: Dictionary, - pluckValue: string): T; + * @see _.find + */ + find( + collection: List|Dictionary, + predicate?: TObject + ): T; } interface LoDashArrayWrapper { /** - * @see _.find - */ + * @see _.find + */ find( + predicate?: ListIterator, + thisArg?: any + ): T; + + /** + * @see _.find + */ + find( + predicate?: string, + thisArg?: any + ): T; + + /** + * @see _.find + */ + find( + predicate?: TObject + ): T; + } + + interface LoDashObjectWrapper { + /** + * @see _.find + */ + find( + predicate?: ListIterator|DictionaryIterator, + thisArg?: any + ): TResult; + + /** + * @see _.find + */ + find( + predicate?: string, + thisArg?: any + ): TResult; + + /** + * @see _.find + */ + find( + predicate?: TObject + ): TResult; + } + + //_.findWhere + interface LoDashStatic { + /** + * @see _.find + **/ + findWhere( + collection: Array, callback: ListIterator, thisArg?: any): T; + + /** + * @see _.find + **/ + findWhere( + collection: List, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + **/ + findWhere( + collection: Dictionary, + callback: DictionaryIterator, + thisArg?: any): T; + /** * @see _.find * @param _.matches style callback - */ - find( + **/ + findWhere( + collection: Array, whereValue: W): T; + /** * @see _.find - * @param _.matchesProperty style callback - */ - find( - path: string, - srcValue: any): T; + * @param _.matches style callback + **/ + findWhere( + collection: List, + whereValue: W): T; + + /** + * @see _.find + * @param _.matches style callback + **/ + findWhere( + collection: Dictionary, + whereValue: W): T; + /** * @see _.find * @param _.property style callback - */ - find( + **/ + findWhere( + collection: Array, + pluckValue: string): T; + + /** + * @see _.find + * @param _.property style callback + **/ + findWhere( + collection: List, + pluckValue: string): T; + + /** + * @see _.find + * @param _.property style callback + **/ + findWhere( + collection: Dictionary, pluckValue: string): T; }