_.forEach/_.each definitions

This commit is contained in:
Brian Zengel
2013-10-18 18:43:33 -04:00
parent ec87d352a2
commit 8d492cb44e
2 changed files with 55 additions and 46 deletions

View File

@@ -219,6 +219,14 @@ 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 = <boolean>_.every([true, 1, null, 'yes'], Boolean);
result = <boolean>_.every(stoogesAges, 'age');
result = <boolean>_.every(stoogesAges, { 'age': 50 });
result = <boolean>_.all([true, 1, null, 'yes'], Boolean);
result = <boolean>_.all(stoogesAges, 'age');
result = <boolean>_.all(stoogesAges, { 'age': 50 });
result = <number>_.find([1, 2, 3, 4], function(num) {
return num % 2 == 0;
});
@@ -237,13 +245,11 @@ result = <number>_.findLast([1, 2, 3, 4], function(num) {
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 });
result = <number[]>_.forEach([1, 2, 3], function(num) { console.log(num); });
result = <_.Dictionary<number>>_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); });
result = <boolean>_.all([true, 1, null, 'yes'], Boolean);
result = <boolean>_.all(stoogesAges, 'age');
result = <boolean>_.all(stoogesAges, { 'age': 50 });
result = <number[]>_.each([1, 2, 3], function(num) { console.log(num); });
result = <_.Dictionary<number>>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); });
result = <any[]>_.map([1, 2, 3], function(num) { return num * 3; });
result = <any[]>_.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; });

83
lodash/lodash.d.ts vendored
View File

@@ -1021,6 +1021,48 @@ declare module _ {
collection: Collection<T>,
pluckValue: string): T;
/**
* Iterates over elements of a collection, executing the callback for each element.
* The callback is bound to thisArg and invoked with three arguments; (value, index|key,
* collection). Callbacks may exit iteration early by explicitly returning false.
* @param collection The collection to iterate over.
* @param callback The function called per iteration.
* @param thisArg The this binding of callback.
**/
export function forEach<T>(
collection: List<T>,
callback: ListIterator<T, void >,
thisArg?: any): List<T>;
/**
* @see _.each
**/
export function forEach<T extends {}>(
object: Dictionary<T>,
callback: ObjectIterator<T, void >,
thisArg?: any): Dictionary<T>;
/**
* @see _.each
**/
export function each<T>(
collection: List<T>,
callback: ListIterator<T, void>,
thisArg?: any): List<T>;
/**
* @see _.each
* @param object Iterators over this object's properties.
* @param iterator Iterator function for each property on `obj`.
* @param context 'this' object in `iterator`, optional.
**/
export function each<T extends {}>(
object: Dictionary<T>,
callback: ObjectIterator<T, void>,
thisArg?: any): Dictionary<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,
@@ -1166,46 +1208,7 @@ declare module _ {
/**
* Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is
* bound to the context object, if one is passed. Each invocation of iterator is called with three
* arguments: (element, index, list). If list is a JavaScript object, iterator's arguments will be
* (value, key, object). Delegates to the native forEach function if it exists.
* @param list Iterates over this list of elements.
* @param iterator Iterator function for each element `list`.
* @param context 'this' object in `iterator`, optional.
**/
export function each<T>(
list: List<T>,
iterator: ListIterator<T, void>,
context?: any): void;
/**
* @see _.each
* @param object Iterators over this object's properties.
* @param iterator Iterator function for each property on `obj`.
* @param context 'this' object in `iterator`, optional.
**/
export function each<T extends {}>(
object: Dictionary<T>,
iterator: ObjectIterator<T, void>,
context?: any): void;
/**
* @see _.each
**/
export function forEach<T>(
list: List<T>,
iterator: ListIterator<T, void >,
context?: any): void;
/**
* @see _.each
**/
export function forEach<T extends {}>(
object: Dictionary<T>,
iterator: ObjectIterator<T, void >,
context?: any): void;
/**
* Also known as inject and foldl, reduce boils down a list of values into a single value.