Merge pull request #7391 from chrootsu/lodash-countBy

lodash: signatures of _.countBy have been changed
This commit is contained in:
Masahiro Wakame
2016-01-09 22:59:14 +09:00
2 changed files with 295 additions and 64 deletions
+131 -6
View File
@@ -3241,13 +3241,138 @@ module TestContains {
}
}
result = <_.Dictionary<number>>_.countBy([4.3, 6.1, 6.4], function (num) { return Math.floor(num); });
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');
// _.countBy
module TestCountBy {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
let numericDictionary: _.NumericDictionary<TResult>;
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_([4.3, 6.1, 6.4]).countBy(function (num) { return Math.floor(num); });
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_([4.3, 6.1, 6.4]).countBy(function (num) { return this.floor(num); }, Math);
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_(['one', 'two', 'three']).countBy('length');
let stringIterator: (value: string, index: number, collection: string) => any;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any;
let numericDictionaryIterator: (value: TResult, key: number, collection: _.NumericDictionary<TResult>) => any;
{
let result: _.Dictionary<number>;
result = _.countBy<string>('');
result = _.countBy<string>('', stringIterator);
result = _.countBy<string>('', stringIterator, any);
result = _.countBy<TResult>(array);
result = _.countBy<TResult>(array, listIterator);
result = _.countBy<TResult>(array, listIterator, any);
result = _.countBy<TResult>(array, '');
result = _.countBy<TResult>(array, '', any);
result = _.countBy<{a: number}, TResult>(array, {a: 42});
result = _.countBy<TResult>(array, {a: 42});
result = _.countBy<TResult>(list);
result = _.countBy<TResult>(list, listIterator);
result = _.countBy<TResult>(list, listIterator, any);
result = _.countBy<TResult>(list, '');
result = _.countBy<TResult>(list, '', any);
result = _.countBy<{a: number}, TResult>(list, {a: 42});
result = _.countBy<TResult>(list, {a: 42});
result = _.countBy<TResult>(dictionary);
result = _.countBy<TResult>(dictionary, dictionaryIterator);
result = _.countBy<TResult>(dictionary, dictionaryIterator, any);
result = _.countBy<TResult>(dictionary, '');
result = _.countBy<TResult>(dictionary, '', any);
result = _.countBy<{a: number}, TResult>(dictionary, {a: 42});
result = _.countBy<TResult>(dictionary, {a: 42});
result = _.countBy<TResult>(numericDictionary);
result = _.countBy<TResult>(numericDictionary, numericDictionaryIterator);
result = _.countBy<TResult>(numericDictionary, numericDictionaryIterator, any);
result = _.countBy<TResult>(numericDictionary, '');
result = _.countBy<TResult>(numericDictionary, '', any);
result = _.countBy<{a: number}, TResult>(numericDictionary, {a: 42});
result = _.countBy<TResult>(numericDictionary, {a: 42});
}
{
let resutl: _.LoDashImplicitObjectWrapper<_.Dictionary<number>>;
result = _('').countBy();
result = _('').countBy(stringIterator);
result = _('').countBy(stringIterator, any);
result = _(array).countBy();
result = _(array).countBy(listIterator);
result = _(array).countBy(listIterator, any);
result = _(array).countBy('');
result = _(array).countBy('', any);
result = _(array).countBy<{a: number}>({a: 42});
result = _(array).countBy({a: 42});
result = _(list).countBy();
result = _(list).countBy<TResult>(listIterator);
result = _(list).countBy<TResult>(listIterator, any);
result = _(list).countBy('');
result = _(list).countBy('', any);
result = _(list).countBy<{a: number}>({a: 42});
result = _(list).countBy({a: 42});
result = _(dictionary).countBy();
result = _(dictionary).countBy<TResult>(dictionaryIterator);
result = _(dictionary).countBy<TResult>(dictionaryIterator, any);
result = _(dictionary).countBy('');
result = _(dictionary).countBy('', any);
result = _(dictionary).countBy<{a: number}>({a: 42});
result = _(dictionary).countBy({a: 42});
result = _(numericDictionary).countBy();
result = _(numericDictionary).countBy<TResult>(numericDictionaryIterator);
result = _(numericDictionary).countBy<TResult>(numericDictionaryIterator, any);
result = _(numericDictionary).countBy('');
result = _(numericDictionary).countBy('', any);
result = _(numericDictionary).countBy<{a: number}>({a: 42});
result = _(numericDictionary).countBy({a: 42});
}
{
let resutl: _.LoDashExplicitObjectWrapper<_.Dictionary<number>>;
result = _('').chain().countBy();
result = _('').chain().countBy(stringIterator);
result = _('').chain().countBy(stringIterator, any);
result = _(array).chain().countBy();
result = _(array).chain().countBy(listIterator);
result = _(array).chain().countBy(listIterator, any);
result = _(array).chain().countBy('');
result = _(array).chain().countBy('', any);
result = _(array).chain().countBy<{a: number}>({a: 42});
result = _(array).chain().countBy({a: 42});
result = _(list).chain().countBy();
result = _(list).chain().countBy<TResult>(listIterator);
result = _(list).chain().countBy<TResult>(listIterator, any);
result = _(list).chain().countBy('');
result = _(list).chain().countBy('', any);
result = _(list).chain().countBy<{a: number}>({a: 42});
result = _(list).chain().countBy({a: 42});
result = _(dictionary).chain().countBy();
result = _(dictionary).chain().countBy<TResult>(dictionaryIterator);
result = _(dictionary).chain().countBy<TResult>(dictionaryIterator, any);
result = _(dictionary).chain().countBy('');
result = _(dictionary).chain().countBy('', any);
result = _(dictionary).chain().countBy<{a: number}>({a: 42});
result = _(dictionary).chain().countBy({a: 42});
result = _(numericDictionary).chain().countBy();
result = _(numericDictionary).chain().countBy<TResult>(numericDictionaryIterator);
result = _(numericDictionary).chain().countBy<TResult>(numericDictionaryIterator, any);
result = _(numericDictionary).chain().countBy('');
result = _(numericDictionary).chain().countBy('', any);
result = _(numericDictionary).chain().countBy<{a: number}>({a: 42});
result = _(numericDictionary).chain().countBy({a: 42});
}
}
// _.detect
module TestDetect {
+164 -58
View File
@@ -4913,87 +4913,193 @@ declare module _ {
//_.countBy
interface LoDashStatic {
/**
* Creates an object composed of keys generated from the results of running each element
* of collection through the callback. The corresponding value of each key is the number
* of times the key was returned by the callback. 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 The collection to iterate over.
* @param callback The function called per iteration.
* @param thisArg The this binding of callback.
* @return Returns the composed aggregate object.
**/
countBy<T>(
collection: Array<T>,
callback?: ListIterator<T, any>,
thisArg?: any): Dictionary<number>;
/**
* @see _.countBy
* @param callback Function name
**/
* Creates an object composed of keys generated from the results of running each element of collection through
* iteratee. The corresponding value of each key is the number of times the key was returned by iteratee. The
* iteratee is bound to thisArg and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for iteratee 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 iteratee the created _.matches style callback returns true for elements that
* have the properties of the given object, else false.
*
* @param collection The collection to iterate over.
* @param iteratee The function invoked per iteration.
* @param thisArg The this binding of iteratee.
* @return Returns the composed aggregate object.
*/
countBy<T>(
collection: List<T>,
callback?: ListIterator<T, any>,
thisArg?: any): Dictionary<number>;
iteratee?: ListIterator<T, any>,
thisArg?: any
): Dictionary<number>;
/**
* @see _.countBy
* @param callback Function name
**/
* @see _.countBy
*/
countBy<T>(
collection: Dictionary<T>,
callback?: DictionaryIterator<T, any>,
thisArg?: any): Dictionary<number>;
iteratee?: DictionaryIterator<T, any>,
thisArg?: any
): Dictionary<number>;
/**
* @see _.countBy
* @param callback Function name
**/
* @see _.countBy
*/
countBy<T>(
collection: Array<T>,
callback: string,
thisArg?: any): Dictionary<number>;
collection: NumericDictionary<T>,
iteratee?: NumericDictionaryIterator<T, any>,
thisArg?: any
): Dictionary<number>;
/**
* @see _.countBy
* @param callback Function name
**/
* @see _.countBy
*/
countBy<T>(
collection: List<T>,
callback: string,
thisArg?: any): Dictionary<number>;
collection: List<T>|Dictionary<T>|NumericDictionary<T>,
iteratee?: string,
thisArg?: any
): Dictionary<number>;
/**
* @see _.countBy
* @param callback Function name
**/
* @see _.countBy
*/
countBy<W, T>(
collection: List<T>|Dictionary<T>|NumericDictionary<T>,
iteratee?: W
): Dictionary<number>;
/**
* @see _.countBy
*/
countBy<T>(
collection: Dictionary<T>,
callback: string,
thisArg?: any): Dictionary<number>;
collection: List<T>|Dictionary<T>|NumericDictionary<T>,
iteratee?: Object
): Dictionary<number>;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.countBy
*/
countBy(
iteratee?: ListIterator<T, any>,
thisArg?: any
): LoDashImplicitObjectWrapper<Dictionary<number>>;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.countBy
**/
* @see _.countBy
*/
countBy(
callback?: ListIterator<T, any>,
thisArg?: any): LoDashImplicitObjectWrapper<Dictionary<number>>;
iteratee?: ListIterator<T, any>,
thisArg?: any
): LoDashImplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
* @param callback Function name
**/
* @see _.countBy
*/
countBy(
callback: string,
thisArg?: any): LoDashImplicitObjectWrapper<Dictionary<number>>;
iteratee?: string,
thisArg?: any
): LoDashImplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
*/
countBy<W>(
iteratee?: W
): LoDashImplicitObjectWrapper<Dictionary<number>>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.countBy
*/
countBy<T>(
iteratee?: ListIterator<T, any>|DictionaryIterator<T, any>|NumericDictionaryIterator<T, any>,
thisArg?: any
): LoDashImplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
*/
countBy(
iteratee?: string,
thisArg?: any
): LoDashImplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
*/
countBy<W>(
iteratee?: W
): LoDashImplicitObjectWrapper<Dictionary<number>>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.countBy
*/
countBy(
iteratee?: ListIterator<T, any>,
thisArg?: any
): LoDashExplicitObjectWrapper<Dictionary<number>>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.countBy
*/
countBy(
iteratee?: ListIterator<T, any>,
thisArg?: any
): LoDashExplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
*/
countBy(
iteratee?: string,
thisArg?: any
): LoDashExplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
*/
countBy<W>(
iteratee?: W
): LoDashExplicitObjectWrapper<Dictionary<number>>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.countBy
*/
countBy<T>(
iteratee?: ListIterator<T, any>|DictionaryIterator<T, any>|NumericDictionaryIterator<T, any>,
thisArg?: any
): LoDashExplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
*/
countBy(
iteratee?: string,
thisArg?: any
): LoDashExplicitObjectWrapper<Dictionary<number>>;
/**
* @see _.countBy
*/
countBy<W>(
iteratee?: W
): LoDashExplicitObjectWrapper<Dictionary<number>>;
}
//_.detect