mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
_.find/_.detect and _.findLast definitions
This commit is contained in:
@@ -219,6 +219,24 @@ result = <_.Dictionary<number>>_.countBy([4.3, 6.1, 6.4], function(num) { return
|
||||
result = <_.Dictionary<number>>_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
|
||||
result = <_.Dictionary<number>>_.countBy(['one', 'two', 'three'], 'length');
|
||||
|
||||
result = <number>_.find([1, 2, 3, 4], function(num) {
|
||||
return num % 2 == 0;
|
||||
});
|
||||
result = <IFoodCombined>_.find(foodsCombined, { 'type': 'vegetable' });
|
||||
result = <IFoodCombined>_.find(foodsCombined, 'organic');
|
||||
|
||||
result = <number>_.detect([1, 2, 3, 4], function(num) {
|
||||
return num % 2 == 0;
|
||||
});
|
||||
result = <IFoodCombined>_.detect(foodsCombined, { 'type': 'vegetable' });
|
||||
result = <IFoodCombined>_.detect(foodsCombined, 'organic');
|
||||
|
||||
result = <number>_.findLast([1, 2, 3, 4], function(num) {
|
||||
return num % 2 == 0;
|
||||
});
|
||||
result = <IFoodCombined>_.findLast(foodsCombined, { 'type': 'vegetable' });
|
||||
result = <IFoodCombined>_.findLast(foodsCombined, 'organic');
|
||||
|
||||
result = <boolean>_.every([true, 1, null, 'yes'], Boolean);
|
||||
result = <boolean>_.every(stoogesAges, 'age');
|
||||
result = <boolean>_.every(stoogesAges, { 'age': 50 });
|
||||
|
||||
Vendored
+89
-26
@@ -932,6 +932,95 @@ declare module _ {
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): boolean;
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*
|
||||
* 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 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.
|
||||
**/
|
||||
export function find<T>(
|
||||
collection: Collection<T>,
|
||||
callback: ListIterator<T, boolean>,
|
||||
thisArg?: any): T;
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
* @param _.pluck style callback
|
||||
**/
|
||||
export function find<T>(
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): T;
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
* @param _.where style callback
|
||||
**/
|
||||
export function find<T>(
|
||||
collection: Collection<T>,
|
||||
pluckValue: string): T;
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
**/
|
||||
export function detect<T>(
|
||||
collection: Collection<T>,
|
||||
callback: ListIterator<T, boolean>,
|
||||
thisArg?: any): T;
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
* @param _.pluck style callback
|
||||
**/
|
||||
export function detect<T>(
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): T;
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
* @param _.where style callback
|
||||
**/
|
||||
export function detect<T>(
|
||||
collection: Collection<T>,
|
||||
pluckValue: string): T;
|
||||
|
||||
/**
|
||||
* This method is like _.find except that it iterates over elements of a collection from
|
||||
* right to left.
|
||||
* @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.
|
||||
**/
|
||||
export function findLast<T>(
|
||||
collection: Collection<T>,
|
||||
callback: ListIterator<T, boolean>,
|
||||
thisArg?: any): T;
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
* @param _.pluck style callback
|
||||
**/
|
||||
export function findLast<T>(
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): T;
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
* @param _.where style callback
|
||||
**/
|
||||
export function findLast<T>(
|
||||
collection: Collection<T>,
|
||||
pluckValue: string): T;
|
||||
|
||||
/**
|
||||
* Creates an array of values by running each element in the collection through the callback.
|
||||
* The callback is bound to thisArg and invoked with three arguments; (value, index|key,
|
||||
@@ -1178,32 +1267,6 @@ declare module _ {
|
||||
memo?: TResult,
|
||||
context?: any): TResult;
|
||||
|
||||
/**
|
||||
* Looks through each value in the list, returning the first one that passes a truth
|
||||
* test (iterator). The function returns as soon as it finds an acceptable element,
|
||||
* and doesn't traverse the entire list.
|
||||
* @param list Searches for a value in this list.
|
||||
* @param iterator Search iterator function for each element in `list`.
|
||||
* @param context `this` object in `iterator`, optional.
|
||||
* @return The first acceptable found element in `list`, if nothing is found undefined/null is returned.
|
||||
**/
|
||||
export function find<T>(
|
||||
list: Collection<T>,
|
||||
iterator: ListIterator<T, boolean>,
|
||||
context?: any): T;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see _.find
|
||||
**/
|
||||
export function detect<T>(
|
||||
list: Collection<T>,
|
||||
iterator: ListIterator<T, boolean>,
|
||||
context?: any): T;
|
||||
|
||||
/**
|
||||
* Looks through each value in the list, returning an array of all the values that pass a truth
|
||||
* test (iterator). Delegates to the native filter method, if it exists.
|
||||
|
||||
Reference in New Issue
Block a user