Merge pull request #6678 from chrootsu/lodash-forEach-forEachRight

lodash: signatures of the methods _.forEach and _.forEachRight have b…
This commit is contained in:
Masahiro Wakame
2015-11-11 19:02:38 +09:00
2 changed files with 392 additions and 103 deletions
+192 -14
View File
@@ -2489,9 +2489,9 @@ module TestEach {
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 stringIterator: (char: string, index: number, string: string) => any;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any;
{
let result: string;
@@ -2578,6 +2578,101 @@ module TestEach {
}
}
// _.eachRight
module TestEachRight {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
let stringIterator: (char: string, index: number, string: string) => any;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any;
{
let result: string;
_.eachRight('', stringIterator);
_.eachRight('', stringIterator, any);
}
{
let result: TResult[];
_.eachRight<TResult>(array, listIterator);
_.eachRight<TResult>(array, listIterator, any);
}
{
let result: _.List<TResult>;
_.eachRight<TResult>(list, listIterator);
_.eachRight<TResult>(list, listIterator, any);
}
{
let result: _.Dictionary<TResult>;
_.eachRight<TResult>(dictionary, dictionaryIterator);
_.eachRight<TResult>(dictionary, dictionaryIterator, any);
}
{
let result: _.LoDashImplicitWrapper<string>;
_('').eachRight(stringIterator);
_('').eachRight(stringIterator, any);
}
{
let result: _.LoDashImplicitArrayWrapper<TResult>;
_(array).eachRight(listIterator);
_(array).eachRight(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.List<TResult>>;
_(list).eachRight<TResult>(listIterator);
_(list).eachRight<TResult>(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).eachRight<TResult>(dictionaryIterator);
_(dictionary).eachRight<TResult>(dictionaryIterator, any);
}
{
let result: _.LoDashExplicitWrapper<string>;
_('').chain().eachRight(stringIterator);
_('').chain().eachRight(stringIterator, any);
}
{
let result: _.LoDashExplicitArrayWrapper<TResult>;
_(array).chain().eachRight(listIterator);
_(array).chain().eachRight(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.List<TResult>>;
_(list).chain().eachRight<TResult>(listIterator);
_(list).chain().eachRight<TResult>(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).chain().eachRight<TResult>(dictionaryIterator);
_(dictionary).chain().eachRight<TResult>(dictionaryIterator, any);
}
}
// _.every
module TestEvery {
let array: TResult[];
@@ -2739,9 +2834,9 @@ module TestForEach {
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 stringIterator: (char: string, index: number, string: string) => any;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any;
{
let result: string;
@@ -2828,17 +2923,100 @@ module TestForEach {
}
}
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); });
// _.forEachRight
module TestForEachRight {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
result = <number[]>_.eachRight([1, 2, 3], function (num) { console.log(num); });
result = <_.Dictionary<number>>_.eachRight({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); });
let stringIterator: (char: string, index: number, string: string) => any;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any;
result = <_.LoDashImplicitArrayWrapper<number>>_([1, 2, 3]).forEachRight(function (num) { console.log(num); });
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEachRight(function (num) { console.log(num); });
{
let result: string;
result = <_.LoDashImplicitArrayWrapper<number>>_([1, 2, 3]).eachRight(function (num) { console.log(num); });
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).eachRight(function (num) { console.log(num); });
_.forEachRight('', stringIterator);
_.forEachRight('', stringIterator, any);
}
{
let result: TResult[];
_.forEachRight<TResult>(array, listIterator);
_.forEachRight<TResult>(array, listIterator, any);
}
{
let result: _.List<TResult>;
_.forEachRight<TResult>(list, listIterator);
_.forEachRight<TResult>(list, listIterator, any);
}
{
let result: _.Dictionary<TResult>;
_.forEachRight<TResult>(dictionary, dictionaryIterator);
_.forEachRight<TResult>(dictionary, dictionaryIterator, any);
}
{
let result: _.LoDashImplicitWrapper<string>;
_('').forEachRight(stringIterator);
_('').forEachRight(stringIterator, any);
}
{
let result: _.LoDashImplicitArrayWrapper<TResult>;
_(array).forEachRight(listIterator);
_(array).forEachRight(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.List<TResult>>;
_(list).forEachRight<TResult>(listIterator);
_(list).forEachRight<TResult>(listIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).forEachRight<TResult>(dictionaryIterator);
_(dictionary).forEachRight<TResult>(dictionaryIterator, any);
}
{
let result: _.LoDashExplicitWrapper<string>;
_('').chain().forEachRight(stringIterator);
_('').chain().forEachRight(stringIterator, any);
}
{
let result: _.LoDashExplicitArrayWrapper<TResult>;
_(array).chain().forEachRight(listIterator);
_(array).chain().forEachRight(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.List<TResult>>;
_(list).chain().forEachRight<TResult>(listIterator);
_(list).chain().forEachRight<TResult>(listIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<TResult>>;
_(dictionary).chain().forEachRight<TResult>(dictionaryIterator);
_(dictionary).chain().forEachRight<TResult>(dictionaryIterator, any);
}
}
result = <_.Dictionary<number[]>>_.groupBy([4.2, 6.1, 6.4], function (num) { return Math.floor(num); });
result = <_.Dictionary<number[]>>_.groupBy([4.2, 6.1, 6.4], function (num) { return this.floor(num); }, Math);
+200 -89
View File
@@ -4109,7 +4109,7 @@ declare module _ {
*/
each(
collection: string,
iteratee?: StringIterator<boolean|void>,
iteratee?: StringIterator<any>,
thisArg?: any
): string;
@@ -4118,7 +4118,7 @@ declare module _ {
*/
each<T>(
collection: T[],
iteratee?: ListIterator<T, boolean|void>,
iteratee?: ListIterator<T, any>,
thisArg?: any
): T[];
@@ -4127,7 +4127,7 @@ declare module _ {
*/
each<T>(
collection: List<T>,
iteratee?: ListIterator<T, boolean|void>,
iteratee?: ListIterator<T, any>,
thisArg?: any
): List<T>;
@@ -4136,7 +4136,7 @@ declare module _ {
*/
each<T>(
collection: Dictionary<T>,
iteratee?: DictionaryIterator<T, boolean|void>,
iteratee?: DictionaryIterator<T, any>,
thisArg?: any
): Dictionary<T>;
}
@@ -4146,7 +4146,7 @@ declare module _ {
* @see _.forEach
*/
each(
iteratee: StringIterator<boolean|void>,
iteratee: StringIterator<any>,
thisArg?: any
): LoDashImplicitWrapper<string>;
}
@@ -4156,7 +4156,7 @@ declare module _ {
* @see _.forEach
*/
each(
iteratee: ListIterator<T, boolean|void>,
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
}
@@ -4166,7 +4166,7 @@ declare module _ {
* @see _.forEach
*/
each<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashImplicitObjectWrapper<T>;
}
@@ -4176,7 +4176,7 @@ declare module _ {
* @see _.forEach
*/
each(
iteratee: StringIterator<boolean|void>,
iteratee: StringIterator<any>,
thisArg?: any
): LoDashExplicitWrapper<string>;
}
@@ -4186,7 +4186,7 @@ declare module _ {
* @see _.forEach
*/
each(
iteratee: ListIterator<T, boolean|void>,
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
}
@@ -4196,7 +4196,106 @@ declare module _ {
* @see _.forEach
*/
each<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashExplicitObjectWrapper<T>;
}
//_.eachRight
interface LoDashStatic {
/**
* @see _.forEachRight
*/
eachRight(
collection: string,
iteratee?: StringIterator<any>,
thisArg?: any
): string;
/**
* @see _.forEachRight
*/
eachRight<T>(
collection: T[],
iteratee?: ListIterator<T, any>,
thisArg?: any
): T[];
/**
* @see _.forEachRight
*/
eachRight<T>(
collection: List<T>,
iteratee?: ListIterator<T, any>,
thisArg?: any
): List<T>;
/**
* @see _.forEachRight
*/
eachRight<T>(
collection: Dictionary<T>,
iteratee?: DictionaryIterator<T, any>,
thisArg?: any
): Dictionary<T>;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.forEachRight
*/
eachRight(
iteratee: StringIterator<any>,
thisArg?: any
): LoDashImplicitWrapper<string>;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.forEachRight
*/
eachRight(
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.forEachRight
*/
eachRight<TValue>(
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashImplicitObjectWrapper<T>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.forEachRight
*/
eachRight(
iteratee: StringIterator<any>,
thisArg?: any
): LoDashExplicitWrapper<string>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.forEachRight
*/
eachRight(
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.forEachRight
*/
eachRight<TValue>(
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashExplicitObjectWrapper<T>;
}
@@ -4932,7 +5031,7 @@ declare module _ {
*/
forEach(
collection: string,
iteratee?: StringIterator<boolean|void>,
iteratee?: StringIterator<any>,
thisArg?: any
): string;
@@ -4941,7 +5040,7 @@ declare module _ {
*/
forEach<T>(
collection: T[],
iteratee?: ListIterator<T, boolean|void>,
iteratee?: ListIterator<T, any>,
thisArg?: any
): T[];
@@ -4950,7 +5049,7 @@ declare module _ {
*/
forEach<T>(
collection: List<T>,
iteratee?: ListIterator<T, boolean|void>,
iteratee?: ListIterator<T, any>,
thisArg?: any
): List<T>;
@@ -4959,7 +5058,7 @@ declare module _ {
*/
forEach<T>(
collection: Dictionary<T>,
iteratee?: DictionaryIterator<T, boolean|void>,
iteratee?: DictionaryIterator<T, any>,
thisArg?: any
): Dictionary<T>;
}
@@ -4969,7 +5068,7 @@ declare module _ {
* @see _.forEach
*/
forEach(
iteratee: StringIterator<boolean|void>,
iteratee: StringIterator<any>,
thisArg?: any
): LoDashImplicitWrapper<string>;
}
@@ -4979,7 +5078,7 @@ declare module _ {
* @see _.forEach
*/
forEach(
iteratee: ListIterator<T, boolean|void>,
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
}
@@ -4989,7 +5088,7 @@ declare module _ {
* @see _.forEach
*/
forEach<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashImplicitObjectWrapper<T>;
}
@@ -4999,7 +5098,7 @@ declare module _ {
* @see _.forEach
*/
forEach(
iteratee: StringIterator<boolean|void>,
iteratee: StringIterator<any>,
thisArg?: any
): LoDashExplicitWrapper<string>;
}
@@ -5009,7 +5108,7 @@ declare module _ {
* @see _.forEach
*/
forEach(
iteratee: ListIterator<T, boolean|void>,
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
}
@@ -5019,7 +5118,7 @@ declare module _ {
* @see _.forEach
*/
forEach<TValue>(
iteratee?: ListIterator<TValue, boolean|void>|DictionaryIterator<TValue, boolean|void>,
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashExplicitObjectWrapper<T>;
}
@@ -5027,94 +5126,106 @@ declare module _ {
//_.forEachRight
interface LoDashStatic {
/**
* This method is like _.forEach except that it iterates over elements of a
* collection from right to left.
* @param collection The collection to iterate over.
* @param callback The function called per iteration.
* @param thisArg The this binding of callback.
**/
forEachRight<T>(
collection: Array<T>,
callback: ListIterator<T, void>,
thisArg?: any): Array<T>;
* This method is like _.forEach except that it iterates over elements of collection from right to left.
*
* @alias _.eachRight
*
* @param collection The collection to iterate over.
* @param iteratee The function called per iteration.
* @param thisArg The this binding of callback.
*/
forEachRight(
collection: string,
iteratee?: StringIterator<any>,
thisArg?: any
): string;
/**
* @see _.forEachRight
**/
* @see _.forEachRight
*/
forEachRight<T>(
collection: T[],
iteratee?: ListIterator<T, any>,
thisArg?: any
): T[];
/**
* @see _.forEachRight
*/
forEachRight<T>(
collection: List<T>,
callback: ListIterator<T, void>,
thisArg?: any): List<T>;
iteratee?: ListIterator<T, any>,
thisArg?: any
): List<T>;
/**
* @see _.forEachRight
**/
forEachRight<T extends {}>(
object: Dictionary<T>,
callback: DictionaryIterator<T, void>,
thisArg?: any): Dictionary<T>;
* @see _.forEachRight
*/
forEachRight<T>(
collection: Dictionary<T>,
iteratee?: DictionaryIterator<T, any>,
thisArg?: any
): Dictionary<T>;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.forEachRight
**/
eachRight<T>(
collection: Array<T>,
callback: ListIterator<T, void>,
thisArg?: any): Array<T>;
/**
* @see _.forEachRight
**/
eachRight<T>(
collection: List<T>,
callback: ListIterator<T, void>,
thisArg?: any): List<T>;
/**
* @see _.forEachRight
* @param object The object to iterate over
* @param callback The function called per iteration.
* @param thisArg The this binding of callback.
**/
eachRight<T extends {}>(
object: Dictionary<T>,
callback: DictionaryIterator<T, void>,
thisArg?: any): Dictionary<T>;
* @see _.forEachRight
*/
forEachRight(
iteratee: StringIterator<any>,
thisArg?: any
): LoDashImplicitWrapper<string>;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.forEachRight
**/
* @see _.forEachRight
*/
forEachRight(
callback: ListIterator<T, void>,
thisArg?: any): LoDashImplicitArrayWrapper<T>;
/**
* @see _.forEachRight
**/
eachRight(
callback: ListIterator<T, void>,
thisArg?: any): LoDashImplicitArrayWrapper<T>;
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.forEachRight
**/
forEachRight<T extends {}>(
callback: ObjectIterator<T, void>,
thisArg?: any): LoDashImplicitObjectWrapper<Dictionary<T>>;
* @see _.forEachRight
*/
forEachRight<TValue>(
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashImplicitObjectWrapper<T>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.forEachRight
* @param object The object to iterate over
* @param callback The function called per iteration.
* @param thisArg The this binding of callback.
**/
eachRight<T extends {}>(
callback: ObjectIterator<T, void>,
thisArg?: any): LoDashImplicitObjectWrapper<Dictionary<T>>;
* @see _.forEachRight
*/
forEachRight(
iteratee: StringIterator<any>,
thisArg?: any
): LoDashExplicitWrapper<string>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.forEachRight
*/
forEachRight(
iteratee: ListIterator<T, any>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.forEachRight
*/
forEachRight<TValue>(
iteratee?: ListIterator<TValue, any>|DictionaryIterator<TValue, any>,
thisArg?: any
): LoDashExplicitObjectWrapper<T>;
}
//_.groupBy