Merge pull request #6250 from chrootsu/lodash-find

lodash: the signatures of the method _.find (and of the alias _.detec...
This commit is contained in:
Masahiro Wakame
2015-10-13 01:32:09 +09:00
2 changed files with 329 additions and 203 deletions

View File

@@ -1322,6 +1322,54 @@ 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');
// _.detect
module TestDetect {
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: TResult;
result = _.detect<TResult>(array);
result = _.detect<TResult>(array, listIterator);
result = _.detect<TResult>(array, listIterator, any);
result = _.detect<TResult>(array, '');
result = _.detect<{a: number}, TResult>(array, {a: 42});
result = _.detect<TResult>(list);
result = _.detect<TResult>(list, listIterator);
result = _.detect<TResult>(list, listIterator, any);
result = _.detect<TResult>(list, '');
result = _.detect<{a: number}, TResult>(list, {a: 42});
result = _.detect<TResult>(dictionary);
result = _.detect<TResult>(dictionary, dictionaryIterator);
result = _.detect<TResult>(dictionary, dictionaryIterator, any);
result = _.detect<TResult>(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<TResult>();
result = _(list).detect<TResult>(listIterator);
result = _(list).detect<TResult>(listIterator, any);
result = _(list).detect<TResult>('');
result = _(list).detect<{a: number}, TResult>({a: 42});
result = _(dictionary).detect<TResult>();
result = _(dictionary).detect<TResult>(dictionaryIterator);
result = _(dictionary).detect<TResult>(dictionaryIterator, any);
result = _(dictionary).detect<TResult>('');
result = _(dictionary).detect<{a: number}, TResult>({a: 42});
}
// _.every
module TestEvery {
let array: TResult[];
@@ -1387,20 +1435,53 @@ result = <number[]>_([1, 2, 3, 4, 5, 6]).select(function (num) { return num % 2
result = <IFoodCombined[]>_(foodsCombined).select('organic').value();
result = <IFoodCombined[]>_(foodsCombined).select({ 'type': 'fruit' }).value();
result = <number>_.find([1, 2, 3, 4], num => num % 2 == 0);
result = <IFoodCombined>_.find(foodsCombined, { 'type': 'vegetable' });
result = <IFoodCombined>_.find(foodsCombined, 'type', 'vegetable');
result = <IFoodCombined>_.find(foodsCombined, 'organic');
result = <number>_([1, 2, 3, 4]).find(num => num % 2 == 0);
result = <IFoodCombined>_(foodsCombined).find({ 'type': 'vegetable' });
result = <IFoodCombined>_(foodsCombined).find('type', 'vegetable');
result = <IFoodCombined>_(foodsCombined).find('organic');
// _.find
module TestFind {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
result = <number>_.detect([1, 2, 3, 4], function (num) {
return num % 2 == 0;
});
result = <IFoodCombined>_.detect(foodsCombined, { 'type': 'vegetable' });
result = <IFoodCombined>_.detect(foodsCombined, 'organic');
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => boolean;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => boolean;
let result: TResult;
result = _.find<TResult>(array);
result = _.find<TResult>(array, listIterator);
result = _.find<TResult>(array, listIterator, any);
result = _.find<TResult>(array, '');
result = _.find<{a: number}, TResult>(array, {a: 42});
result = _.find<TResult>(list);
result = _.find<TResult>(list, listIterator);
result = _.find<TResult>(list, listIterator, any);
result = _.find<TResult>(list, '');
result = _.find<{a: number}, TResult>(list, {a: 42});
result = _.find<TResult>(dictionary);
result = _.find<TResult>(dictionary, dictionaryIterator);
result = _.find<TResult>(dictionary, dictionaryIterator, any);
result = _.find<TResult>(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<TResult>();
result = _(list).find<TResult>(listIterator);
result = _(list).find<TResult>(listIterator, any);
result = _(list).find<TResult>('');
result = _(list).find<{a: number}, TResult>({a: 42});
result = _(dictionary).find<TResult>();
result = _(dictionary).find<TResult>(dictionaryIterator);
result = _(dictionary).find<TResult>(dictionaryIterator, any);
result = _(dictionary).find<TResult>('');
result = _(dictionary).find<{a: number}, TResult>({a: 42});
}
result = <number>_.findWhere([1, 2, 3, 4], function (num) {
return num % 2 == 0;

425
lodash/lodash.d.ts vendored
View File

@@ -3012,6 +3012,94 @@ declare module _ {
thisArg?: any): LoDashObjectWrapper<Dictionary<number>>;
}
//_.detect
interface LoDashStatic {
/**
* @see _.find
*/
detect<T>(
collection: List<T>,
predicate?: ListIterator<T, boolean>,
thisArg?: any
): T;
/**
* @see _.find
*/
detect<T>(
collection: Dictionary<T>,
predicate?: DictionaryIterator<T, boolean>,
thisArg?: any
): T;
/**
* @see _.find
*/
detect<T>(
collection: List<T>|Dictionary<T>,
predicate?: string,
thisArg?: any
): T;
/**
* @see _.find
*/
detect<TObject extends {}, T>(
collection: List<T>|Dictionary<T>,
predicate?: TObject
): T;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.find
*/
detect(
predicate?: ListIterator<T, boolean>,
thisArg?: any
): T;
/**
* @see _.find
*/
detect(
predicate?: string,
thisArg?: any
): T;
/**
* @see _.find
*/
detect<TObject extends {}>(
predicate?: TObject
): T;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.find
*/
detect<TResult>(
predicate?: ListIterator<TResult, boolean>|DictionaryIterator<TResult, boolean>,
thisArg?: any
): TResult;
/**
* @see _.find
*/
detect<TResult>(
predicate?: string,
thisArg?: any
): TResult;
/**
* @see _.find
*/
detect<TObject extends {}, TResult>(
predicate?: TObject
): TResult;
}
//_.every
interface LoDashStatic {
/**
@@ -3396,223 +3484,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<T>(
collection: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T;
/**
* Alias of _.find
* @see _.find
**/
detect<T>(
collection: Array<T>,
callback: ListIterator<T, boolean>,
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<T>(
collection: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T;
predicate?: ListIterator<T, boolean>,
thisArg?: any
): T;
/**
* Alias of _.find
* @see _.find
**/
detect<T>(
collection: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
**/
* @see _.find
*/
find<T>(
collection: Dictionary<T>,
callback: DictionaryIterator<T, boolean>,
thisArg?: any): T;
predicate?: DictionaryIterator<T, boolean>,
thisArg?: any
): T;
/**
* Alias of _.find
* @see _.find
**/
detect<T>(
collection: Dictionary<T>,
callback: DictionaryIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
* @param _.matches style callback
**/
find<W, T>(
collection: Array<T>|List<T>|Dictionary<T>,
whereValue: W): T;
/**
* Alias of _.find
* @see _.find
* @param _.matches style callback
**/
detect<W, T>(
collection: Array<T>|List<T>|Dictionary<T>,
whereValue: W): T;
/**
* @see _.find
* @param _.matchesProperty style callback
**/
* @see _.find
*/
find<T>(
collection: Array<T>|List<T>|Dictionary<T>,
path: string,
srcValue: any): T;
collection: List<T>|Dictionary<T>,
predicate?: string,
thisArg?: any
): T;
/**
* Alias of _.find
* @see _.find
* @param _.matchesProperty style callback
**/
detect<T>(
collection: Array<T>|List<T>|Dictionary<T>,
path: string,
srcValue: any): T;
/**
* @see _.find
* @param _.property style callback
**/
find<T>(
collection: Array<T>|List<T>|Dictionary<T>,
pluckValue: string): T;
/**
* Alias of _.find
* @see _.find
* @param _.property style callback
**/
detect<T>(
collection: Array<T>|List<T>|Dictionary<T>,
pluckValue: string): T;
/**
* @see _.find
**/
findWhere<T>(
collection: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
**/
findWhere<T>(
collection: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
**/
findWhere<T>(
collection: Dictionary<T>,
callback: DictionaryIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
* @param _.matches style callback
**/
findWhere<W, T>(
collection: Array<T>,
whereValue: W): T;
/**
* @see _.find
* @param _.matches style callback
**/
findWhere<W, T>(
collection: List<T>,
whereValue: W): T;
/**
* @see _.find
* @param _.matches style callback
**/
findWhere<W, T>(
collection: Dictionary<T>,
whereValue: W): T;
/**
* @see _.find
* @param _.property style callback
**/
findWhere<T>(
collection: Array<T>,
pluckValue: string): T;
/**
* @see _.find
* @param _.property style callback
**/
findWhere<T>(
collection: List<T>,
pluckValue: string): T;
/**
* @see _.find
* @param _.property style callback
**/
findWhere<T>(
collection: Dictionary<T>,
pluckValue: string): T;
* @see _.find
*/
find<TObject extends {}, T>(
collection: List<T>|Dictionary<T>,
predicate?: TObject
): T;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.find
*/
* @see _.find
*/
find(
predicate?: ListIterator<T, boolean>,
thisArg?: any
): T;
/**
* @see _.find
*/
find(
predicate?: string,
thisArg?: any
): T;
/**
* @see _.find
*/
find<TObject extends {}>(
predicate?: TObject
): T;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.find
*/
find<TResult>(
predicate?: ListIterator<TResult, boolean>|DictionaryIterator<TResult, boolean>,
thisArg?: any
): TResult;
/**
* @see _.find
*/
find<TResult>(
predicate?: string,
thisArg?: any
): TResult;
/**
* @see _.find
*/
find<TObject extends {}, TResult>(
predicate?: TObject
): TResult;
}
//_.findWhere
interface LoDashStatic {
/**
* @see _.find
**/
findWhere<T>(
collection: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
**/
findWhere<T>(
collection: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
**/
findWhere<T>(
collection: Dictionary<T>,
callback: DictionaryIterator<T, boolean>,
thisArg?: any): T;
/**
* @see _.find
* @param _.matches style callback
*/
find<W>(
**/
findWhere<W, T>(
collection: Array<T>,
whereValue: W): T;
/**
* @see _.find
* @param _.matchesProperty style callback
*/
find(
path: string,
srcValue: any): T;
* @param _.matches style callback
**/
findWhere<W, T>(
collection: List<T>,
whereValue: W): T;
/**
* @see _.find
* @param _.matches style callback
**/
findWhere<W, T>(
collection: Dictionary<T>,
whereValue: W): T;
/**
* @see _.find
* @param _.property style callback
*/
find(
**/
findWhere<T>(
collection: Array<T>,
pluckValue: string): T;
/**
* @see _.find
* @param _.property style callback
**/
findWhere<T>(
collection: List<T>,
pluckValue: string): T;
/**
* @see _.find
* @param _.property style callback
**/
findWhere<T>(
collection: Dictionary<T>,
pluckValue: string): T;
}