lodash: signatures of the method _.forEach have been changed

This commit is contained in:
Ilya Mochalov
2015-11-03 07:09:19 +05:00
parent 0dd29bf825
commit b3833f87dd
2 changed files with 375 additions and 101 deletions
+186 -18
View File
@@ -2267,6 +2267,101 @@ module TestDetect {
result = _(dictionary).detect<{a: number}, TResult>({a: 42});
}
// _.each
module TestEach {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
let stringIterator: (char: string, index: number, string: string) => boolean|void;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => boolean|void;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => boolean|void;
{
let result: string;
_.each('', stringIterator);
_.each('', stringIterator, any);
}
{
let result: TResult[];
_.each<TResult>(array, listIterator);
_.each<TResult>(array, listIterator, any);
}
{
let result: _.List<TResult>;
_.each<TResult>(list, listIterator);
_.each<TResult>(list, listIterator, any);
}
{
let result: _.Dictionary<TResult>;
_.each<TResult>(dictionary, dictionaryIterator);
_.each<TResult>(dictionary, dictionaryIterator, any);
}
{
let result: _.LoDashImplicitWrapper<string>;
_('').each(stringIterator);
_('').each(stringIterator, any);
}
{
let result: _.LoDashImplicitArrayWrapper<TResult>;
_(array).each(listIterator);
_(array).each(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.List<TResult>>;
_(list).each<TResult>(listIterator);
_(list).each<TResult>(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).each<TResult>(dictionaryIterator);
_(dictionary).each<TResult>(dictionaryIterator, any);
}
{
let result: _.LoDashExplicitWrapper<string>;
_('').chain().each(stringIterator);
_('').chain().each(stringIterator, any);
}
{
let result: _.LoDashExplicitArrayWrapper<TResult>;
_(array).chain().each(listIterator);
_(array).chain().each(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.List<TResult>>;
_(list).chain().each<TResult>(listIterator);
_(list).chain().each<TResult>(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).chain().each<TResult>(dictionaryIterator);
_(dictionary).chain().each<TResult>(dictionaryIterator, any);
}
}
// _.every
module TestEvery {
let array: TResult[];
@@ -2422,19 +2517,100 @@ result = <number>_([1, 2, 3, 4]).findLast(function (num) {
result = <IFoodCombined>_(foodsCombined).findLast({ 'type': 'vegetable' });
result = <IFoodCombined>_(foodsCombined).findLast('organic');
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 = <IFoodType>_.forEach<IFoodType, string>({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) });
// _.forEach
module TestForEach {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
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 = <IFoodType>_.each<IFoodType, string>({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) });
let stringIterator: (char: string, index: number, string: string) => boolean|void;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => boolean|void;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => boolean|void;
result = <_.LoDashImplicitArrayWrapper<number>>_([1, 2, 3]).forEach(function (num) { console.log(num); });
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEach(function (num) { console.log(num); });
{
let result: string;
result = <_.LoDashImplicitArrayWrapper<number>>_([1, 2, 3]).each(function (num) { console.log(num); });
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).each(function (num) { console.log(num); });
_.forEach('', stringIterator);
_.forEach('', stringIterator, any);
}
{
let result: TResult[];
_.forEach<TResult>(array, listIterator);
_.forEach<TResult>(array, listIterator, any);
}
{
let result: _.List<TResult>;
_.forEach<TResult>(list, listIterator);
_.forEach<TResult>(list, listIterator, any);
}
{
let result: _.Dictionary<TResult>;
_.forEach<TResult>(dictionary, dictionaryIterator);
_.forEach<TResult>(dictionary, dictionaryIterator, any);
}
{
let result: _.LoDashImplicitWrapper<string>;
_('').forEach(stringIterator);
_('').forEach(stringIterator, any);
}
{
let result: _.LoDashImplicitArrayWrapper<TResult>;
_(array).forEach(listIterator);
_(array).forEach(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.List<TResult>>;
_(list).forEach<TResult>(listIterator);
_(list).forEach<TResult>(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).forEach<TResult>(dictionaryIterator);
_(dictionary).forEach<TResult>(dictionaryIterator, any);
}
{
let result: _.LoDashExplicitWrapper<string>;
_('').chain().forEach(stringIterator);
_('').chain().forEach(stringIterator, any);
}
{
let result: _.LoDashExplicitArrayWrapper<TResult>;
_(array).chain().forEach(listIterator);
_(array).chain().forEach(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.List<TResult>>;
_(list).chain().forEach<TResult>(listIterator);
_(list).chain().forEach<TResult>(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).chain().forEach<TResult>(dictionaryIterator);
_(dictionary).chain().forEach<TResult>(dictionaryIterator, any);
}
}
result = <number[]>_.forEachRight([1, 2, 3], function (num) { console.log(num); });
result = <_.Dictionary<number>>_.forEachRight({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); });
@@ -2788,18 +2964,10 @@ done = _.after(saves.length, function () {
console.log('Done saving!');
});
_.forEach(saves, function (type) {
asyncSave({ 'type': type, 'complete': done });
});
done = _(saves.length).after(function () {
console.log('Done saving!');
}).value();
_.forEach(saves, function (type) {
asyncSave({ 'type': type, 'complete': done });
});
// _.ary
result = <number[]>['6', '8', '10'].map(_.ary<(s: string) => number>(parseInt, 1));
result = <number[]>['6', '8', '10'].map(_(parseInt).ary<(s: string) => number>(1).value());
+189 -83
View File
@@ -3804,6 +3804,105 @@ declare module _ {
): TResult;
}
//_.each
interface LoDashStatic {
/**
* @see _.forEach
*/
each(
collection: string,
iteratee?: StringIterator<boolean|void>,
thisArg?: any
): string;
/**
* @see _.forEach
*/
each<T>(
collection: T[],
iteratee?: ListIterator<T, boolean|void>,
thisArg?: any
): T[];
/**
* @see _.forEach
*/
each<T>(
collection: List<T>,
iteratee?: ListIterator<T, boolean|void>,
thisArg?: any
): List<T>;
/**
* @see _.forEach
*/
each<T>(
collection: Dictionary<T>,
iteratee?: DictionaryIterator<T, boolean|void>,
thisArg?: any
): Dictionary<T>;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.forEach
*/
each(
iteratee: StringIterator<boolean|void>,
thisArg?: any
): LoDashImplicitWrapper<string>;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.forEach
*/
each(
iteratee: ListIterator<T, boolean|void>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.forEach
*/
each<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
thisArg?: any
): LoDashImplicitObjectWrapper<T>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.forEach
*/
each(
iteratee: StringIterator<boolean|void>,
thisArg?: any
): LoDashExplicitWrapper<string>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.forEach
*/
each(
iteratee: ListIterator<T, boolean|void>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.forEach
*/
each<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
thisArg?: any
): LoDashExplicitObjectWrapper<T>;
}
//_.every
interface LoDashStatic {
/**
@@ -4520,108 +4619,111 @@ declare module _ {
//_.forEach
interface LoDashStatic {
/**
* 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.
**/
forEach<T>(
collection: Array<T>,
callback: ListIterator<T, void>,
thisArg?: any): Array<T>;
* Iterates over elements of collection invoking iteratee for each element. The iteratee is bound to thisArg
* and invoked with three arguments:
* (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.
*
* Note: As with other "Collections" methods, objects with a "length" property are iterated like arrays. To
* avoid this behavior _.forIn or _.forOwn may be used for object iteration.
*
* @alias _.each
*
* @param collection The collection to iterate over.
* @param iteratee The function invoked per iteration.
* @param thisArg The this binding of iteratee.
*/
forEach(
collection: string,
iteratee?: StringIterator<boolean|void>,
thisArg?: any
): string;
/**
* @see _.forEach
**/
* @see _.forEach
*/
forEach<T>(
collection: T[],
iteratee?: ListIterator<T, boolean|void>,
thisArg?: any
): T[];
/**
* @see _.forEach
*/
forEach<T>(
collection: List<T>,
callback: ListIterator<T, void>,
thisArg?: any): List<T>;
iteratee?: ListIterator<T, boolean|void>,
thisArg?: any
): List<T>;
/**
* @see _.forEach
**/
forEach<T extends {}>(
object: Dictionary<T>,
callback: DictionaryIterator<T, void>,
thisArg?: any): Dictionary<T>;
* @see _.forEach
*/
forEach<T>(
collection: Dictionary<T>,
iteratee?: DictionaryIterator<T, boolean|void>,
thisArg?: any
): Dictionary<T>;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.each
**/
forEach<T extends {}, TValue>(
object: T,
callback: ObjectIterator<TValue, void>,
thisArg?: any): T
/**
* @see _.forEach
**/
each<T>(
collection: Array<T>,
callback: ListIterator<T, void>,
thisArg?: any): Array<T>;
/**
* @see _.forEach
**/
each<T>(
collection: List<T>,
callback: ListIterator<T, void>,
thisArg?: any): List<T>;
/**
* @see _.forEach
* @param object The object to iterate over
* @param callback The function called per iteration.
* @param thisArg The this binding of callback.
**/
each<T extends {}>(
object: Dictionary<T>,
callback: DictionaryIterator<T, void>,
thisArg?: any): Dictionary<T>;
/**
* @see _.each
**/
each<T extends {}, TValue>(
object: T,
callback: ObjectIterator<TValue, void>,
thisArg?: any): T
* @see _.forEach
*/
forEach(
iteratee: StringIterator<boolean|void>,
thisArg?: any
): LoDashImplicitWrapper<string>;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.forEach
**/
* @see _.forEach
*/
forEach(
callback: ListIterator<T, void>,
thisArg?: any): LoDashImplicitArrayWrapper<T>;
/**
* @see _.forEach
**/
each(
callback: ListIterator<T, void>,
thisArg?: any): LoDashImplicitArrayWrapper<T>;
iteratee: ListIterator<T, boolean|void>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.forEach
**/
forEach<T extends {}>(
callback: ObjectIterator<T, void>,
thisArg?: any): LoDashImplicitObjectWrapper<T>;
* @see _.forEach
*/
forEach<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
thisArg?: any
): LoDashImplicitObjectWrapper<T>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.forEach
**/
each<T extends {}>(
callback: ObjectIterator<T, void>,
thisArg?: any): LoDashImplicitObjectWrapper<T>;
* @see _.forEach
*/
forEach(
iteratee: StringIterator<boolean|void>,
thisArg?: any
): LoDashExplicitWrapper<string>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.forEach
*/
forEach(
iteratee: ListIterator<T, boolean|void>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.forEach
*/
forEach<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
thisArg?: any
): LoDashExplicitObjectWrapper<T>;
}
//_.forEachRight
@@ -11043,6 +11145,10 @@ declare module _ {
(element: T, key?: string, collection?: any): TResult;
}
interface StringIterator<TResult> {
(char: string, index?: number, string?: string): TResult;
}
interface MemoVoidIterator<T, TResult> {
(prev: TResult, curr: T, indexOrKey?: any, list?: T[]): void;
}