lodash: changed _.every() method (and alias _.all())

This commit is contained in:
Ilya Mochalov
2015-10-04 04:50:32 +05:00
parent 98d3168c2c
commit 80ff55a5b8
2 changed files with 263 additions and 143 deletions
+94 -6
View File
@@ -650,6 +650,54 @@ result = <number[]>_([1, 2]).zipWith<number>([1, 2], [1, 2], [1, 2], [1, 2], [1,
* Collection *
**************/
// _.all
module TestAll {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => boolean;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => boolean;
let result: boolean;
result = _.all<TResult>(array);
result = _.all<TResult>(array, listIterator);
result = _.all<TResult>(array, listIterator, any);
result = _.all<TResult>(array, '');
result = _.all<{a: number}, TResult>(array, {a: 42});
result = _.all<TResult>(list);
result = _.all<TResult>(list, listIterator);
result = _.all<TResult>(list, listIterator, any);
result = _.all<TResult>(list, '');
result = _.all<{a: number}, TResult>(list, {a: 42});
result = _.all<TResult>(dictionary);
result = _.all<TResult>(dictionary, dictionaryIterator);
result = _.all<TResult>(dictionary, dictionaryIterator, any);
result = _.all<TResult>(dictionary, '');
result = _.all<{a: number}, TResult>(dictionary, {a: 42});
result = _(array).all();
result = _(array).all(listIterator);
result = _(array).all(listIterator, any);
result = _(array).all('');
result = _(array).all<{a: number}>({a: 42});
result = _(list).all<TResult>();
result = _(list).all<TResult>(listIterator);
result = _(list).all<TResult>(listIterator, any);
result = _(list).all('');
result = _(list).all<{a: number}>({a: 42});
result = _(dictionary).all<TResult>();
result = _(dictionary).all<TResult>(dictionaryIterator);
result = _(dictionary).all<TResult>(dictionaryIterator, any);
result = _(dictionary).all('');
result = _(dictionary).all<{a: number}>({a: 42});
}
// _.at
{
let testAtArray: TResult[];
@@ -747,13 +795,53 @@ result = <_.LoDashObjectWrapper<_.Dictionary<number>>>_([4.3, 6.1, 6.4]).countBy
result = <_.LoDashObjectWrapper<_.Dictionary<number>>>_([4.3, 6.1, 6.4]).countBy(function (num) { return this.floor(num); }, Math);
result = <_.LoDashObjectWrapper<_.Dictionary<number>>>_(['one', 'two', 'three']).countBy('length');
result = <boolean>_.every([true, 1, null, 'yes'], Boolean);
result = <boolean>_.every(stoogesAges, 'age');
result = <boolean>_.every(stoogesAges, { 'age': 50 });
// _.every
module TestEvery {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
result = <boolean>_.all([true, 1, null, 'yes'], Boolean);
result = <boolean>_.all(stoogesAges, 'age');
result = <boolean>_.all(stoogesAges, { 'age': 50 });
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => boolean;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => boolean;
let result: boolean;
result = _.every<TResult>(array);
result = _.every<TResult>(array, listIterator);
result = _.every<TResult>(array, listIterator, any);
result = _.every<TResult>(array, '');
result = _.every<{a: number}, TResult>(array, {a: 42});
result = _.every<TResult>(list);
result = _.every<TResult>(list, listIterator);
result = _.every<TResult>(list, listIterator, any);
result = _.every<TResult>(list, '');
result = _.every<{a: number}, TResult>(list, {a: 42});
result = _.every<TResult>(dictionary);
result = _.every<TResult>(dictionary, dictionaryIterator);
result = _.every<TResult>(dictionary, dictionaryIterator, any);
result = _.every<TResult>(dictionary, '');
result = _.every<{a: number}, TResult>(dictionary, {a: 42});
result = _(array).every();
result = _(array).every(listIterator);
result = _(array).every(listIterator, any);
result = _(array).every('');
result = _(array).every<{a: number}>({a: 42});
result = _(list).every<TResult>();
result = _(list).every<TResult>(listIterator);
result = _(list).every<TResult>(listIterator, any);
result = _(list).every('');
result = _(list).every<{a: number}>({a: 42});
result = _(dictionary).every<TResult>();
result = _(dictionary).every<TResult>(dictionaryIterator);
result = _(dictionary).every<TResult>(dictionaryIterator, any);
result = _(dictionary).every('');
result = _(dictionary).every<{a: number}>({a: 42});
}
result = <number[]>_.filter([1, 2, 3, 4, 5, 6]);
result = <number[]>_.filter([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; });
+169 -137
View File
@@ -2004,6 +2004,94 @@ declare module _ {
* Collection *
**************/
//_.all
interface LoDashStatic {
/**
* @see _.every
*/
all<T>(
collection: List<T>,
predicate?: ListIterator<T, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
*/
all<T>(
collection: Dictionary<T>,
predicate?: DictionaryIterator<T, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
*/
all<T>(
collection: List<T>|Dictionary<T>,
predicate?: string,
thisArg?: any
): boolean;
/**
* @see _.every
*/
all<TObject extends {}, T>(
collection: List<T>|Dictionary<T>,
predicate?: TObject
): boolean;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.every
*/
all(
predicate?: ListIterator<T, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
*/
all(
predicate?: string,
thisArg?: any
): boolean;
/**
* @see _.every
*/
all<TObject extends {}>(
predicate?: TObject
): boolean;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.every
*/
all<TResult>(
predicate?: ListIterator<TResult, boolean>|DictionaryIterator<TResult, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
*/
all(
predicate?: string,
thisArg?: any
): boolean;
/**
* @see _.every
*/
all<TObject extends {}>(
predicate?: TObject
): boolean;
}
//_.at
interface LoDashStatic {
/**
@@ -2383,162 +2471,106 @@ declare module _ {
//_.every
interface LoDashStatic {
/**
* Checks if the given callback returns truey value for all elements of a 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 all elements passed the callback check, else false.
**/
every<T>(
collection: Array<T>,
callback?: ListIterator<T, boolean>,
thisArg?: any): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
* Checks if predicate returns truthy for all elements of 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 _.all
*
* @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 all elements pass the predicate check, else false.
*/
every<T>(
collection: List<T>,
callback?: ListIterator<T, boolean>,
thisArg?: any): boolean;
predicate?: ListIterator<T, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
* @see _.every
*/
every<T>(
collection: Dictionary<T>,
callback?: DictionaryIterator<T, boolean>,
thisArg?: any): boolean;
predicate?: DictionaryIterator<T, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
* @see _.every
*/
every<T>(
collection: Array<T>,
pluckValue: string): boolean;
collection: List<T>|Dictionary<T>,
predicate?: string,
thisArg?: any
): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
every<T>(
collection: List<T>,
pluckValue: string): boolean;
* @see _.every
*/
every<TObject extends {}, T>(
collection: List<T>|Dictionary<T>,
predicate?: TObject
): boolean;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.every
*/
every(
predicate?: ListIterator<T, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
every<T>(
collection: Dictionary<T>,
pluckValue: string): boolean;
* @see _.every
*/
every(
predicate?: string,
thisArg?: any
): boolean;
/**
* @see _.every
* @param whereValue _.where style callback
**/
every<W, T>(
collection: Array<T>,
whereValue: W): boolean;
* @see _.every
*/
every<TObject extends {}>(
predicate?: TObject
): boolean;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.every
*/
every<TResult>(
predicate?: ListIterator<TResult, boolean>|DictionaryIterator<TResult, boolean>,
thisArg?: any
): boolean;
/**
* @see _.every
* @param whereValue _.where style callback
**/
every<W, T>(
collection: List<T>,
whereValue: W): boolean;
* @see _.every
*/
every(
predicate?: string,
thisArg?: any
): boolean;
/**
* @see _.every
* @param whereValue _.where style callback
**/
every<W, T>(
collection: Dictionary<T>,
whereValue: W): boolean;
/**
* @see _.every
**/
all<T>(
collection: Array<T>,
callback?: ListIterator<T, boolean>,
thisArg?: any): boolean;
/**
* @see _.every
**/
all<T>(
collection: List<T>,
callback?: ListIterator<T, boolean>,
thisArg?: any): boolean;
/**
* @see _.every
**/
all<T>(
collection: Dictionary<T>,
callback?: DictionaryIterator<T, boolean>,
thisArg?: any): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
all<T>(
collection: Array<T>,
pluckValue: string): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
all<T>(
collection: List<T>,
pluckValue: string): boolean;
/**
* @see _.every
* @param pluckValue _.pluck style callback
**/
all<T>(
collection: Dictionary<T>,
pluckValue: string): boolean;
/**
* @see _.every
* @param whereValue _.where style callback
**/
all<W, T>(
collection: Array<T>,
whereValue: W): boolean;
/**
* @see _.every
* @param whereValue _.where style callback
**/
all<W, T>(
collection: List<T>,
whereValue: W): boolean;
/**
* @see _.every
* @param whereValue _.where style callback
**/
all<W, T>(
collection: Dictionary<T>,
whereValue: W): boolean;
* @see _.every
*/
every<TObject extends {}>(
predicate?: TObject
): boolean;
}
//_.fill