diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 633c4ed0d4..193f87c08c 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -403,15 +403,13 @@ 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], function (num) { - return num % 2 == 0; -}); +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(function (num) { - return num % 2 == 0; -}); +result = _([1, 2, 3, 4]).find(num => num % 2 == 0); result = _(foodsCombined).find({ 'type': 'vegetable' }); +result = _(foodsCombined).find('type', 'vegetable'); result = _(foodsCombined).find('organic'); result = _.detect([1, 2, 3, 4], function (num) { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 9cb55485d9..faf921c57c 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2710,15 +2710,19 @@ declare module _ { //_.find interface LoDashStatic { /** - * Iterates over elements of a collection, returning the first element that the callback - * returns truey for. The callback is bound to thisArg and invoked with three arguments; - * (value, index|key, collection). + * 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 callback the created "_.pluck" style callback will - * return the property value of the given element. + * If a property name is provided for predicate the created _.property style callback + * returns the property value of the given element. * - * If an object is provided for callback the created "_.where" style callback will return + * 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. @@ -2728,6 +2732,10 @@ declare module _ { collection: Array, callback: ListIterator, thisArg?: any): T; + detect( + collection: Array, + callback: ListIterator, + thisArg?: any): T; /** * @see _.find @@ -2736,6 +2744,10 @@ declare module _ { collection: List, callback: ListIterator, thisArg?: any): T; + detect( + collection: List, + callback: ListIterator, + thisArg?: any): T; /** * @see _.find @@ -2744,74 +2756,6 @@ declare module _ { collection: Dictionary, callback: DictionaryIterator, thisArg?: any): T; - - /** - * @see _.find - * @param _.pluck style callback - **/ - find( - collection: Array, - whereValue: W): T; - - /** - * @see _.find - * @param _.pluck style callback - **/ - find( - collection: List, - whereValue: W): T; - - /** - * @see _.find - * @param _.pluck style callback - **/ - find( - collection: Dictionary, - whereValue: W): T; - - /** - * @see _.find - * @param _.where style callback - **/ - find( - collection: Array, - pluckValue: string): T; - - /** - * @see _.find - * @param _.where style callback - **/ - find( - collection: List, - pluckValue: string): T; - - /** - * @see _.find - * @param _.where style callback - **/ - find( - collection: Dictionary, - pluckValue: string): T; - - /** - * @see _.find - **/ - detect( - collection: Array, - callback: ListIterator, - thisArg?: any): T; - - /** - * @see _.find - **/ - detect( - collection: List, - callback: ListIterator, - thisArg?: any): T; - - /** - * @see _.find - **/ detect( collection: Dictionary, callback: DictionaryIterator, @@ -2819,50 +2763,37 @@ declare module _ { /** * @see _.find - * @param _.pluck style callback + * @param _.matches style callback **/ + find( + collection: Array|List|Dictionary, + whereValue: W): T; detect( - collection: Array, + collection: Array|List|Dictionary, whereValue: W): T; /** * @see _.find - * @param _.pluck style callback - **/ - detect( - collection: List, - whereValue: W): T; - - /** - * @see _.find - * @param _.pluck style callback - **/ - detect( - collection: Dictionary, - whereValue: W): T; - - /** - * @see _.find - * @param _.where style callback + * @param _.matchesProperty style callback **/ + find( + collection: Array|List|Dictionary, + path: string, + srcValue: any): T; detect( - collection: Array, + collection: Array|List|Dictionary, + path: string, + srcValue: any): T; + + /** + * @see _.find + * @param _.property style callback + **/ + find( + collection: Array|List|Dictionary, pluckValue: string): T; - - /** - * @see _.find - * @param _.where style callback - **/ detect( - collection: List, - pluckValue: string): T; - - /** - * @see _.find - * @param _.where style callback - **/ - detect( - collection: Dictionary, + collection: Array|List|Dictionary, pluckValue: string): T; /** @@ -2891,7 +2822,7 @@ declare module _ { /** * @see _.find - * @param _.pluck style callback + * @param _.matches style callback **/ findWhere( collection: Array, @@ -2899,7 +2830,7 @@ declare module _ { /** * @see _.find - * @param _.pluck style callback + * @param _.matches style callback **/ findWhere( collection: List, @@ -2907,7 +2838,7 @@ declare module _ { /** * @see _.find - * @param _.pluck style callback + * @param _.matches style callback **/ findWhere( collection: Dictionary, @@ -2915,7 +2846,7 @@ declare module _ { /** * @see _.find - * @param _.where style callback + * @param _.property style callback **/ findWhere( collection: Array, @@ -2923,7 +2854,7 @@ declare module _ { /** * @see _.find - * @param _.where style callback + * @param _.property style callback **/ findWhere( collection: List, @@ -2931,7 +2862,7 @@ declare module _ { /** * @see _.find - * @param _.where style callback + * @param _.property style callback **/ findWhere( collection: Dictionary, @@ -2947,14 +2878,20 @@ declare module _ { thisArg?: any): T; /** * @see _.find - * @param _.where style callback + * @param _.matches style callback */ find( whereValue: W): T; - /** * @see _.find - * @param _.where style callback + * @param _.matchesProperty style callback + */ + find( + path: string, + srcValue: any): T; + /** + * @see _.find + * @param _.property style callback */ find( pluckValue: string): T;