From d454b4d8dc41acb18bebf581b1a3ebff89b1b0f3 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sun, 11 Oct 2015 04:16:07 +0500 Subject: [PATCH] lodash: changed signatures of the method _.some (and alias _.any) --- lodash/lodash-tests.ts | 102 ++++++++++++- lodash/lodash.d.ts | 329 ++++++++++++++++++++++------------------- 2 files changed, 268 insertions(+), 163 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index db15ebc4a..532e740a0 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -961,6 +961,54 @@ module TestAll { result = _(dictionary).all<{a: number}>({a: 42}); } +// _.any +module TestAny { + 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: boolean; + + result = _.any(array); + result = _.any(array, listIterator); + result = _.any(array, listIterator, any); + result = _.any(array, ''); + result = _.any<{a: number}, TResult>(array, {a: 42}); + + result = _.any(list); + result = _.any(list, listIterator); + result = _.any(list, listIterator, any); + result = _.any(list, ''); + result = _.any<{a: number}, TResult>(list, {a: 42}); + + result = _.any(dictionary); + result = _.any(dictionary, dictionaryIterator); + result = _.any(dictionary, dictionaryIterator, any); + result = _.any(dictionary, ''); + result = _.any<{a: number}, TResult>(dictionary, {a: 42}); + + result = _(array).any(); + result = _(array).any(listIterator); + result = _(array).any(listIterator, any); + result = _(array).any(''); + result = _(array).any<{a: number}>({a: 42}); + + result = _(list).any(); + result = _(list).any(listIterator); + result = _(list).any(listIterator, any); + result = _(list).any(''); + result = _(list).any<{a: number}>({a: 42}); + + result = _(dictionary).any(); + result = _(dictionary).any(dictionaryIterator); + result = _(dictionary).any(dictionaryIterator, any); + result = _(dictionary).any(''); + result = _(dictionary).any<{a: number}>({a: 42}); +} + // _.at { let testAtArray: TResult[]; @@ -1448,15 +1496,53 @@ result = _.size({ 'one': 1, 'two': 2, 'three': 3 }); result = _({ 'one': 1, 'two': 2, 'three': 3 }).size(); result = _.size('curly'); -result = _.some([null, 0, 'yes', false], Boolean); -result = _.some(foodsCombined, 'organic'); -result = _.some(foodsCombined, { 'type': 'meat' }); -result = _.some(foodsOrganic[0]); +// _.some +module TestSome { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; -result = _.any([null, 0, 'yes', false], Boolean); -result = _.any(foodsCombined, 'organic'); -result = _.any(foodsCombined, { 'type': 'meat' }); -result = _.any(foodsOrganic[0]); + let listIterator: (value: TResult, index: number, collection: _.List) => boolean; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => boolean; + + let result: boolean; + + result = _.some(array); + result = _.some(array, listIterator); + result = _.some(array, listIterator, any); + result = _.some(array, ''); + result = _.some<{a: number}, TResult>(array, {a: 42}); + + result = _.some(list); + result = _.some(list, listIterator); + result = _.some(list, listIterator, any); + result = _.some(list, ''); + result = _.some<{a: number}, TResult>(list, {a: 42}); + + result = _.some(dictionary); + result = _.some(dictionary, dictionaryIterator); + result = _.some(dictionary, dictionaryIterator, any); + result = _.some(dictionary, ''); + result = _.some<{a: number}, TResult>(dictionary, {a: 42}); + + result = _(array).some(); + result = _(array).some(listIterator); + result = _(array).some(listIterator, any); + result = _(array).some(''); + result = _(array).some<{a: number}>({a: 42}); + + result = _(list).some(); + result = _(list).some(listIterator); + result = _(list).some(listIterator, any); + result = _(list).some(''); + result = _(list).some<{a: number}>({a: 42}); + + result = _(dictionary).some(); + result = _(dictionary).some(dictionaryIterator); + result = _(dictionary).some(dictionaryIterator, any); + result = _(dictionary).some(''); + result = _(dictionary).some<{a: number}>({a: 42}); +} result = _.sortBy([1, 2, 3], function (num) { return Math.sin(num); }); result = _.sortBy([1, 2, 3], function (num) { return this.sin(num); }, Math); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 5a3e0df9e..99c2fe37f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2419,6 +2419,94 @@ declare module _ { ): boolean; } + //_.any + interface LoDashStatic { + /** + * @see _.some + */ + any( + collection: List, + predicate?: ListIterator, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + any( + collection: Dictionary, + predicate?: DictionaryIterator, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + any( + collection: List|Dictionary, + predicate?: string, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + any( + collection: List|Dictionary, + predicate?: TObject + ): boolean; + } + + interface LoDashArrayWrapper { + /** + * @see _.some + */ + any( + predicate?: ListIterator, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + any( + predicate?: string, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + any( + predicate?: TObject + ): boolean; + } + + interface LoDashObjectWrapper { + /** + * @see _.some + */ + any( + predicate?: ListIterator|DictionaryIterator, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + any( + predicate?: string, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + any( + predicate?: TObject + ): boolean; + } + //_.at interface LoDashStatic { /** @@ -5283,176 +5371,107 @@ declare module _ { //_.some interface LoDashStatic { /** - * Checks if the callback returns a truey value for any element of a collection. The function - * returns as soon as it finds a passing value and does not iterate over the entire collection. - * 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 thisArg The this binding of callback. - * @return True if any element passed the callback check, else false. - **/ - some( - collection: Array, - callback?: ListIterator, - thisArg?: any): boolean; - - /** - * @see _.some - **/ + * Checks if predicate returns truthy for any element of collection. The function returns as soon as it finds + * a passing value and does not iterate over the entire collection. 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 _.any + * + * @param collection The collection to iterate over. + * @param predicate The function invoked per iteration. + * @param thisArg The this binding of predicate. + * @return Returns true if any element passes the predicate check, else false. + */ some( collection: List, - callback?: ListIterator, - thisArg?: any): boolean; - - /** - * @see _.some - **/ - some( - collection: Dictionary, - callback?: DictionaryIterator, - thisArg?: any): boolean; + predicate?: ListIterator, + thisArg?: any + ): boolean; /** * @see _.some - **/ + */ + some( + collection: Dictionary, + predicate?: DictionaryIterator, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + some( + collection: List|Dictionary, + predicate?: string, + thisArg?: any + ): boolean; + + /** + * @see _.some + */ + some( + collection: List|Dictionary, + predicate?: TObject + ): boolean; + } + + interface LoDashArrayWrapper { + /** + * @see _.some + */ some( - collection: {}, - callback?: ListIterator<{}, boolean>, - thisArg?: any): boolean; - - /** - * @see _.some - * @param pluckValue _.pluck style callback - **/ - some( - collection: Array, - pluckValue: string): boolean; - - /** - * @see _.some - * @param pluckValue _.pluck style callback - **/ - some( - collection: List, - pluckValue: string): boolean; - - /** - * @see _.some - * @param pluckValue _.pluck style callback - **/ - some( - collection: Dictionary, - pluckValue: string): boolean; - - /** - * @see _.some - * @param whereValue _.where style callback - **/ - some( - collection: Array, - whereValue: W): boolean; - - /** - * @see _.some - * @param whereValue _.where style callback - **/ - some( - collection: List, - whereValue: W): boolean; - - /** - * @see _.some - * @param whereValue _.where style callback - **/ - some( - collection: Dictionary, - whereValue: W): boolean; - - /** - * @see _.some - **/ - any( - collection: Array, - callback?: ListIterator, - thisArg?: any): boolean; - - /** - * @see _.some - **/ - any( - collection: List, - callback?: ListIterator, - thisArg?: any): boolean; - - /** - * @see _.some - **/ - any( - collection: Dictionary, - callback?: DictionaryIterator, - thisArg?: any): boolean; + predicate?: ListIterator, + thisArg?: any + ): boolean; /** * @see _.some - **/ - any( - collection: {}, - callback?: ListIterator<{}, boolean>, - thisArg?: any): boolean; + */ + some( + predicate?: string, + thisArg?: any + ): boolean; /** - * @see _.some - * @param pluckValue _.pluck style callback - **/ - any( - collection: Array, - pluckValue: string): boolean; + * @see _.some + */ + some( + predicate?: TObject + ): boolean; + } + + interface LoDashObjectWrapper { + /** + * @see _.some + */ + some( + predicate?: ListIterator|DictionaryIterator, + thisArg?: any + ): boolean; /** - * @see _.some - * @param pluckValue _.pluck style callback - **/ - any( - collection: List, - pluckValue: string): boolean; + * @see _.some + */ + some( + predicate?: string, + thisArg?: any + ): boolean; /** - * @see _.some - * @param pluckValue _.pluck style callback - **/ - any( - collection: Dictionary, - pluckValue: string): boolean; - - /** - * @see _.some - * @param whereValue _.where style callback - **/ - any( - collection: Array, - whereValue: W): boolean; - - /** - * @see _.some - * @param whereValue _.where style callback - **/ - any( - collection: List, - whereValue: W): boolean; - - /** - * @see _.some - * @param whereValue _.where style callback - **/ - any( - collection: Dictionary, - whereValue: W): boolean; + * @see _.some + */ + some( + predicate?: TObject + ): boolean; } //_.sortBy