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

This commit is contained in:
Ilya Mochalov
2015-11-14 18:10:58 +05:00
parent efd40e67ff
commit fd3b5297fa
2 changed files with 495 additions and 208 deletions
+192 -13
View File
@@ -2745,22 +2745,103 @@ module TestEvery {
}
}
result = <number[]>_.filter([1, 2, 3, 4, 5, 6]);
result = <number[]>_.filter([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; });
result = <IFoodCombined[]>_.filter(foodsCombined, 'organic');
result = <IFoodCombined[]>_.filter(foodsCombined, { 'type': 'fruit' });
// _.filter
module TestFilter {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
result = <number[]>_([1, 2, 3, 4, 5, 6]).filter(function (num) { return num % 2 == 0; }).value();
result = <IFoodCombined[]>_(foodsCombined).filter('organic').value();
result = <IFoodCombined[]>_(foodsCombined).filter({ 'type': 'fruit' }).value();
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 = <number[]>_.select([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; });
result = <IFoodCombined[]>_.select(foodsCombined, 'organic');
result = <IFoodCombined[]>_.select(foodsCombined, { 'type': 'fruit' });
{
let result: string[];
result = <number[]>_([1, 2, 3, 4, 5, 6]).select(function (num) { return num % 2 == 0; }).value();
result = <IFoodCombined[]>_(foodsCombined).select('organic').value();
result = <IFoodCombined[]>_(foodsCombined).select({ 'type': 'fruit' }).value();
result = _.filter('', stringIterator);
result = _.filter('', stringIterator, any);
}
{
let result: TResult[];
result = _.filter<TResult>(array, listIterator);
result = _.filter<TResult>(array, listIterator, any);
result = _.filter<TResult>(array, '');
result = _.filter<TResult>(array, '', any);
result = _.filter<{a: number}, TResult>(array, {a: 42});
result = _.filter<TResult>(list, listIterator);
result = _.filter<TResult>(list, listIterator, any);
result = _.filter<TResult>(list, '');
result = _.filter<TResult>(list, '', any);
result = _.filter<{a: number}, TResult>(list, {a: 42});
result = _.filter<TResult>(dictionary, dictionaryIterator);
result = _.filter<TResult>(dictionary, dictionaryIterator, any);
result = _.filter<TResult>(dictionary, '');
result = _.filter<TResult>(dictionary, '', any);
result = _.filter<{a: number}, TResult>(dictionary, {a: 42});
}
{
let result: _.LoDashImplicitArrayWrapper<string>;
result = _('').filter(stringIterator);
result = _('').filter(stringIterator, any);
}
{
let result: _.LoDashImplicitArrayWrapper<TResult>;
result = _(array).filter(listIterator);
result = _(array).filter(listIterator, any);
result = _(array).filter('');
result = _(array).filter('', any);
result = _(array).filter<{a: number}>({a: 42});
result = _(list).filter<TResult>(listIterator);
result = _(list).filter<TResult>(listIterator, any);
result = _(list).filter<TResult>('');
result = _(list).filter<TResult>('', any);
result = _(list).filter<{a: number}, TResult>({a: 42});
result = _(dictionary).filter<TResult>(dictionaryIterator);
result = _(dictionary).filter<TResult>(dictionaryIterator, any);
result = _(dictionary).filter<TResult>('');
result = _(dictionary).filter<TResult>('', any);
result = _(dictionary).filter<{a: number}, TResult>({a: 42});
}
{
let result: _.LoDashExplicitArrayWrapper<string>;
result = _('').chain().filter(stringIterator);
result = _('').chain().filter(stringIterator, any);
}
{
let result: _.LoDashExplicitArrayWrapper<TResult>;
result = _(array).chain().filter(listIterator);
result = _(array).chain().filter(listIterator, any);
result = _(array).chain().filter('');
result = _(array).chain().filter('', any);
result = _(array).chain().filter<{a: number}>({a: 42});
result = _(list).chain().filter<TResult>(listIterator);
result = _(list).chain().filter<TResult>(listIterator, any);
result = _(list).chain().filter<TResult>('');
result = _(list).chain().filter<TResult>('', any);
result = _(list).chain().filter<{a: number}, TResult>({a: 42});
result = _(dictionary).chain().filter<TResult>(dictionaryIterator);
result = _(dictionary).chain().filter<TResult>(dictionaryIterator, any);
result = _(dictionary).chain().filter<TResult>('');
result = _(dictionary).chain().filter<TResult>('', any);
result = _(dictionary).chain().filter<{a: number}, TResult>({a: 42});
}
}
// _.find
module TestFind {
@@ -3296,6 +3377,104 @@ result = <_.LoDashImplicitArrayWrapper<number>>_([1, 2, 3, 4]).sample(2);
result = <number>_([1, 2, 3, 4]).sample().value();
result = <number[]>_([1, 2, 3, 4]).sample(2).value();
// _.select
module TestSelect {
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[];
result = _.select('', stringIterator);
result = _.select('', stringIterator, any);
}
{
let result: TResult[];
result = _.select<TResult>(array, listIterator);
result = _.select<TResult>(array, listIterator, any);
result = _.select<TResult>(array, '');
result = _.select<TResult>(array, '', any);
result = _.select<{a: number}, TResult>(array, {a: 42});
result = _.select<TResult>(list, listIterator);
result = _.select<TResult>(list, listIterator, any);
result = _.select<TResult>(list, '');
result = _.select<TResult>(list, '', any);
result = _.select<{a: number}, TResult>(list, {a: 42});
result = _.select<TResult>(dictionary, dictionaryIterator);
result = _.select<TResult>(dictionary, dictionaryIterator, any);
result = _.select<TResult>(dictionary, '');
result = _.select<TResult>(dictionary, '', any);
result = _.select<{a: number}, TResult>(dictionary, {a: 42});
}
{
let result: _.LoDashImplicitArrayWrapper<string>;
result = _('').select(stringIterator);
result = _('').select(stringIterator, any);
}
{
let result: _.LoDashImplicitArrayWrapper<TResult>;
result = _(array).select(listIterator);
result = _(array).select(listIterator, any);
result = _(array).select('');
result = _(array).select('', any);
result = _(array).select<{a: number}>({a: 42});
result = _(list).select<TResult>(listIterator);
result = _(list).select<TResult>(listIterator, any);
result = _(list).select<TResult>('');
result = _(list).select<TResult>('', any);
result = _(list).select<{a: number}, TResult>({a: 42});
result = _(dictionary).select<TResult>(dictionaryIterator);
result = _(dictionary).select<TResult>(dictionaryIterator, any);
result = _(dictionary).select<TResult>('');
result = _(dictionary).select<TResult>('', any);
result = _(dictionary).select<{a: number}, TResult>({a: 42});
}
{
let result: _.LoDashExplicitArrayWrapper<string>;
result = _('').chain().select(stringIterator);
result = _('').chain().select(stringIterator, any);
}
{
let result: _.LoDashExplicitArrayWrapper<TResult>;
result = _(array).chain().select(listIterator);
result = _(array).chain().select(listIterator, any);
result = _(array).chain().select('');
result = _(array).chain().select('', any);
result = _(array).chain().select<{a: number}>({a: 42});
result = _(list).chain().select<TResult>(listIterator);
result = _(list).chain().select<TResult>(listIterator, any);
result = _(list).chain().select<TResult>('');
result = _(list).chain().select<TResult>('', any);
result = _(list).chain().select<{a: number}, TResult>({a: 42});
result = _(dictionary).chain().select<TResult>(dictionaryIterator);
result = _(dictionary).chain().select<TResult>(dictionaryIterator, any);
result = _(dictionary).chain().select<TResult>('');
result = _(dictionary).chain().select<TResult>('', any);
result = _(dictionary).chain().select<{a: number}, TResult>({a: 42});
}
}
// _.shuffle
module TestShuffle {
let array: TResult[];
+303 -195
View File
@@ -4507,228 +4507,177 @@ declare module _ {
//_.filter
interface LoDashStatic {
/**
* Iterates over elements of a collection, returning an array of all elements the
* identity function returns truey for.
*
* @param collection The collection to iterate over.
* @return Returns a new array of elements that passed the callback check.
**/
filter<T>(
collection: (Array<T>|List<T>)): T[];
/**
* Iterates over elements of a collection, returning an array of all elements 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 The collection to iterate over.
* @param callback The function called per iteration.
* @param context The this binding of callback.
* @return Returns a new array of elements that passed the callback check.
**/
filter<T>(
collection: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.filter
**/
* Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The
* predicate is bound to thisArg and invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for predicate 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 predicate the created _.matches style callback returns true for elements that
* have the properties of the given object, else false.
*
* @alias _.select
*
* @param collection The collection to iterate over.
* @param predicate The function invoked per iteration.
* @param thisArg The this binding of predicate.
* @return Returns the new filtered array.
*/
filter<T>(
collection: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
predicate?: ListIterator<T, boolean>,
thisArg?: any
): T[];
/**
* @see _.filter
**/
* @see _.filter
*/
filter<T>(
collection: Dictionary<T>,
callback: DictionaryIterator<T, boolean>,
thisArg?: any): T[];
predicate?: DictionaryIterator<T, boolean>,
thisArg?: any
): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
* @see _.filter
*/
filter(
collection: string,
predicate?: StringIterator<boolean>,
thisArg?: any
): string[];
/**
* @see _.filter
*/
filter<T>(
collection: Array<T>,
pluckValue: string): T[];
collection: List<T>|Dictionary<T>,
predicate: string,
thisArg?: any
): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
filter<T>(
collection: List<T>,
pluckValue: string): T[];
* @see _.filter
*/
filter<W extends {}, T>(
collection: List<T>|Dictionary<T>,
predicate: W
): T[];
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
filter<T>(
collection: Dictionary<T>,
pluckValue: string): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
filter<W, T>(
collection: Array<T>,
whereValue: W): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
filter<W, T>(
collection: List<T>,
whereValue: W): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
filter<W, T>(
collection: Dictionary<T>,
whereValue: W): T[];
/**
* @see _.filter
**/
select<T>(
collection: Array<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.filter
**/
select<T>(
collection: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.filter
**/
select<T>(
collection: Dictionary<T>,
callback: DictionaryIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select<T>(
collection: Array<T>,
pluckValue: string): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select<T>(
collection: List<T>,
pluckValue: string): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select<T>(
collection: Dictionary<T>,
pluckValue: string): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select<W, T>(
collection: Array<T>,
whereValue: W): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select<W, T>(
collection: List<T>,
whereValue: W): T[];
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select<W, T>(
collection: Dictionary<T>,
whereValue: W): T[];
* @see _.filter
*/
filter(
predicate?: StringIterator<boolean>,
thisArg?: any
): LoDashImplicitArrayWrapper<string>;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.filter
**/
filter(): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
**/
* @see _.filter
*/
filter(
callback: ListIterator<T, boolean>,
thisArg?: any): LoDashImplicitArrayWrapper<T>;
predicate: ListIterator<T, boolean>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
* @see _.filter
*/
filter(
pluckValue: string): LoDashImplicitArrayWrapper<T>;
predicate: string,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
filter<W>(
whereValue: W): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
**/
select(
callback: ListIterator<T, boolean>,
thisArg?: any): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select(
pluckValue: string): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
* @param pluckValue _.pluck style callback
**/
select<W>(
whereValue: W): LoDashImplicitArrayWrapper<T>;
* @see _.filter
*/
filter<W>(predicate: W): LoDashImplicitArrayWrapper<T>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.filter
**/
filter<T extends {}>(
callback: ObjectIterator<T, boolean>,
thisArg?: any): LoDashImplicitObjectWrapper<T>;
* @see _.filter
*/
filter<T>(
predicate: ListIterator<T, boolean>|DictionaryIterator<T, boolean>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
*/
filter<T>(
predicate: string,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
*/
filter<W, T>(predicate: W): LoDashImplicitArrayWrapper<T>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.filter
*/
filter(
predicate?: StringIterator<boolean>,
thisArg?: any
): LoDashExplicitArrayWrapper<string>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.filter
*/
filter(
predicate: ListIterator<T, boolean>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
filter(
predicate: string,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
filter<W>(predicate: W): LoDashExplicitArrayWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.filter
*/
filter<T>(
predicate: ListIterator<T, boolean>|DictionaryIterator<T, boolean>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
filter<T>(
predicate: string,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
filter<W, T>(predicate: W): LoDashExplicitArrayWrapper<T>;
}
//_.find
@@ -6362,6 +6311,165 @@ declare module _ {
sample(): LoDashImplicitWrapper<T>;
}
//_.select
interface LoDashStatic {
/**
* @see _.filter
*/
select<T>(
collection: List<T>,
predicate?: ListIterator<T, boolean>,
thisArg?: any
): T[];
/**
* @see _.filter
*/
select<T>(
collection: Dictionary<T>,
predicate?: DictionaryIterator<T, boolean>,
thisArg?: any
): T[];
/**
* @see _.filter
*/
select(
collection: string,
predicate?: StringIterator<boolean>,
thisArg?: any
): string[];
/**
* @see _.filter
*/
select<T>(
collection: List<T>|Dictionary<T>,
predicate: string,
thisArg?: any
): T[];
/**
* @see _.filter
*/
select<W extends {}, T>(
collection: List<T>|Dictionary<T>,
predicate: W
): T[];
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.filter
*/
select(
predicate?: StringIterator<boolean>,
thisArg?: any
): LoDashImplicitArrayWrapper<string>;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.filter
*/
select(
predicate: ListIterator<T, boolean>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select(
predicate: string,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select<W>(predicate: W): LoDashImplicitArrayWrapper<T>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.filter
*/
select<T>(
predicate: ListIterator<T, boolean>|DictionaryIterator<T, boolean>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select<T>(
predicate: string,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select<W, T>(predicate: W): LoDashImplicitArrayWrapper<T>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.filter
*/
select(
predicate?: StringIterator<boolean>,
thisArg?: any
): LoDashExplicitArrayWrapper<string>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.filter
*/
select(
predicate: ListIterator<T, boolean>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select(
predicate: string,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select<W>(predicate: W): LoDashExplicitArrayWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.filter
*/
select<T>(
predicate: ListIterator<T, boolean>|DictionaryIterator<T, boolean>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select<T>(
predicate: string,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.filter
*/
select<W, T>(predicate: W): LoDashExplicitArrayWrapper<T>;
}
//_.shuffle
interface LoDashStatic {
/**