From d485633bf2193a432701e937f9f1f01641a9daef Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Tue, 2 Feb 2016 17:57:09 +0500 Subject: [PATCH] lodash: changed _.some --- lodash/lodash-tests.ts | 114 +++++++++++++++++++++-------------------- lodash/lodash.d.ts | 51 +++++------------- 2 files changed, 72 insertions(+), 93 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 66f0bf2ca..97cde614a 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -4380,65 +4380,67 @@ module TestSize { } // _.some -module TestSome { - let array: TResult[]; - let list: _.List; - let dictionary: _.Dictionary; - let numericDictionary: _.NumericDictionary; +namespace TestSome { + type SampleObject = {a: number; b: string; c: boolean;}; - let listIterator: (value: TResult, index: number, collection: _.List) => boolean; - let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => boolean; - let numericDictionaryIterator: (value: TResult, key: number, collection: _.NumericDictionary) => boolean; + let array: SampleObject[]; + let list: _.List; + let dictionary: _.Dictionary; + let numericDictionary: _.NumericDictionary; + + let listIterator: (value: SampleObject, index: number, collection: _.List) => boolean; + let dictionaryIterator: (value: SampleObject, key: string, collection: _.Dictionary) => boolean; + let numericDictionaryIterator: (value: SampleObject, key: number, collection: _.NumericDictionary) => 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(array); + result = _.some(array, listIterator); + result = _.some(array, 'a'); + result = _.some(array, ['a', 42]); + result = _.some<{a: number}, SampleObject>(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(list); + result = _.some(list, listIterator); + result = _.some(list, 'a'); + result = _.some(list, ['a', 42]); + result = _.some<{a: number}, SampleObject>(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 = _.some(dictionary); + result = _.some(dictionary, dictionaryIterator); + result = _.some(dictionary, 'a'); + result = _.some(dictionary, ['a', 42]); + result = _.some<{a: number}, SampleObject>(dictionary, {a: 42}); - result = _.some(numericDictionary); - result = _.some(numericDictionary, numericDictionaryIterator); - result = _.some(numericDictionary, numericDictionaryIterator, any); - result = _.some(numericDictionary, ''); - result = _.some<{a: number}, TResult>(numericDictionary, {a: 42}); + result = _.some(numericDictionary); + result = _.some(numericDictionary, numericDictionaryIterator); + result = _.some(numericDictionary, 'a'); + result = _.some(numericDictionary, ['a', 42]); + result = _.some<{a: number}, SampleObject>(numericDictionary, {a: 42}); result = _(array).some(); result = _(array).some(listIterator); - result = _(array).some(listIterator, any); - result = _(array).some(''); + result = _(array).some('a'); + result = _(array).some(['a', 42]); 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(); + result = _(list).some(listIterator); + result = _(list).some('a'); + result = _(list).some(['a', 42]); 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(); + result = _(dictionary).some(dictionaryIterator); + result = _(dictionary).some('a'); + result = _(dictionary).some(['a', 42]); result = _(dictionary).some<{a: number}>({a: 42}); - result = _(numericDictionary).some(); - result = _(numericDictionary).some(numericDictionaryIterator); - result = _(numericDictionary).some(numericDictionaryIterator, any); - result = _(numericDictionary).some(''); + result = _(numericDictionary).some(); + result = _(numericDictionary).some(numericDictionaryIterator); + result = _(numericDictionary).some('a'); + result = _(numericDictionary).some(['a', 42]); result = _(numericDictionary).some<{a: number}>({a: 42}); } @@ -4447,26 +4449,26 @@ module TestSome { result = _(array).chain().some(); result = _(array).chain().some(listIterator); - result = _(array).chain().some(listIterator, any); - result = _(array).chain().some(''); + result = _(array).chain().some('a'); + result = _(array).chain().some(['a', 42]); result = _(array).chain().some<{a: number}>({a: 42}); - result = _(list).chain().some(); - result = _(list).chain().some(listIterator); - result = _(list).chain().some(listIterator, any); - result = _(list).chain().some(''); + result = _(list).chain().some(); + result = _(list).chain().some(listIterator); + result = _(list).chain().some('a'); + result = _(list).chain().some(['a', 42]); result = _(list).chain().some<{a: number}>({a: 42}); - result = _(dictionary).chain().some(); - result = _(dictionary).chain().some(dictionaryIterator); - result = _(dictionary).chain().some(dictionaryIterator, any); - result = _(dictionary).chain().some(''); + result = _(dictionary).chain().some(); + result = _(dictionary).chain().some(dictionaryIterator); + result = _(dictionary).chain().some('a'); + result = _(dictionary).chain().some(['a', 42]); result = _(dictionary).chain().some<{a: number}>({a: 42}); - result = _(numericDictionary).chain().some(); - result = _(numericDictionary).chain().some(numericDictionaryIterator); - result = _(numericDictionary).chain().some(numericDictionaryIterator, any); - result = _(numericDictionary).chain().some(''); + result = _(numericDictionary).chain().some(); + result = _(numericDictionary).chain().some(numericDictionaryIterator); + result = _(numericDictionary).chain().some('a'); + result = _(numericDictionary).chain().some(['a', 42]); result = _(numericDictionary).chain().some<{a: number}>({a: 42}); } } diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index aaa8dc7e3..47b8e1765 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -7700,28 +7700,16 @@ declare module _ { //_.some interface LoDashStatic { /** - * 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. + * Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate + * returns truthy. The predicate is invoked with three arguments: (value, index|key, collection). * * @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, - predicate?: ListIterator, - thisArg?: any + predicate?: ListIterator ): boolean; /** @@ -7729,8 +7717,7 @@ declare module _ { */ some( collection: Dictionary, - predicate?: DictionaryIterator, - thisArg?: any + predicate?: DictionaryIterator ): boolean; /** @@ -7738,8 +7725,7 @@ declare module _ { */ some( collection: NumericDictionary, - predicate?: NumericDictionaryIterator, - thisArg?: any + predicate?: NumericDictionaryIterator ): boolean; /** @@ -7747,8 +7733,7 @@ declare module _ { */ some( collection: List|Dictionary|NumericDictionary, - predicate?: string, - thisArg?: any + predicate?: string|any[] ): boolean; /** @@ -7765,16 +7750,14 @@ declare module _ { * @see _.some */ some( - predicate?: ListIterator|NumericDictionaryIterator, - thisArg?: any + predicate?: ListIterator|NumericDictionaryIterator ): boolean; /** * @see _.some */ some( - predicate?: string, - thisArg?: any + predicate?: string|any[] ): boolean; /** @@ -7790,16 +7773,14 @@ declare module _ { * @see _.some */ some( - predicate?: ListIterator|DictionaryIterator|NumericDictionaryIterator, - thisArg?: any + predicate?: ListIterator|DictionaryIterator|NumericDictionaryIterator ): boolean; /** * @see _.some */ some( - predicate?: string, - thisArg?: any + predicate?: string|any[] ): boolean; /** @@ -7815,16 +7796,14 @@ declare module _ { * @see _.some */ some( - predicate?: ListIterator|NumericDictionaryIterator, - thisArg?: any + predicate?: ListIterator|NumericDictionaryIterator ): LoDashExplicitWrapper; /** * @see _.some */ some( - predicate?: string, - thisArg?: any + predicate?: string|any[] ): LoDashExplicitWrapper; /** @@ -7840,16 +7819,14 @@ declare module _ { * @see _.some */ some( - predicate?: ListIterator|DictionaryIterator|NumericDictionaryIterator, - thisArg?: any + predicate?: ListIterator|DictionaryIterator|NumericDictionaryIterator ): LoDashExplicitWrapper; /** * @see _.some */ some( - predicate?: string, - thisArg?: any + predicate?: string|any[] ): LoDashExplicitWrapper; /**