Merge pull request #6600 from chrootsu/lodash-sortBy

lodash: signatures of the method _.sortBy have been changed
This commit is contained in:
Masahiro Wakame
2015-11-05 22:43:55 +09:00
2 changed files with 235 additions and 93 deletions
+75 -6
View File
@@ -2964,9 +2964,81 @@ module TestSome {
}
}
result = <number[]>_.sortBy([1, 2, 3], function (num) { return Math.sin(num); });
result = <number[]>_.sortBy([1, 2, 3], function (num) { return this.sin(num); }, Math);
result = <string[]>_.sortBy(['banana', 'strawberry', 'apple'], 'length');
// _.sortBy
module TestSortBy {
let array: TResult[];
let list: _.List<TResult>;
let dictionary: _.Dictionary<TResult>;
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => number;
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => number;
{
let result: TResult[];
result = _.sortBy<TResult>(array);
result = _.sortBy<TResult, number>(array, listIterator);
result = _.sortBy<TResult, number>(array, listIterator, any);
result = _.sortBy<TResult>(array, '');
result = _.sortBy<{a: number}, TResult>(array, {a: 42});
result = _.sortBy<TResult>(list);
result = _.sortBy<TResult, number>(list, listIterator);
result = _.sortBy<TResult, number>(list, listIterator, any);
result = _.sortBy<TResult>(list, '');
result = _.sortBy<{a: number}, TResult>(list, {a: 42});
result = _.sortBy<TResult>(dictionary);
result = _.sortBy<TResult, number>(dictionary, dictionaryIterator);
result = _.sortBy<TResult, number>(dictionary, dictionaryIterator, any);
result = _.sortBy<TResult>(dictionary, '');
result = _.sortBy<{a: number}, TResult>(dictionary, {a: 42});
}
{
let result: _.LoDashImplicitArrayWrapper<TResult>;
result = _(array).sortBy();
result = _(array).sortBy<number>(listIterator);
result = _(array).sortBy<number>(listIterator, any);
result = _(array).sortBy('');
result = _(array).sortBy<{a: number}>({a: 42});
result = _(list).sortBy<TResult>();
result = _(list).sortBy<TResult, number>(listIterator);
result = _(list).sortBy<TResult, number>(listIterator, any);
result = _(list).sortBy<TResult>('');
result = _(list).sortBy<{a: number}, TResult>({a: 42});
result = _(dictionary).sortBy<TResult>();
result = _(dictionary).sortBy<TResult, number>(dictionaryIterator);
result = _(dictionary).sortBy<TResult, number>(dictionaryIterator, any);
result = _(dictionary).sortBy<TResult>('');
result = _(dictionary).sortBy<{a: number}, TResult>({a: 42});
}
{
let result: _.LoDashExplicitArrayWrapper<TResult>;
result = _(array).chain().sortBy();
result = _(array).chain().sortBy<number>(listIterator);
result = _(array).chain().sortBy<number>(listIterator, any);
result = _(array).chain().sortBy('');
result = _(array).chain().sortBy<{a: number}>({a: 42});
result = _(list).chain().sortBy<TResult>();
result = _(list).chain().sortBy<TResult, number>(listIterator);
result = _(list).chain().sortBy<TResult, number>(listIterator, any);
result = _(list).chain().sortBy<TResult>('');
result = _(list).chain().sortBy<{a: number}, TResult>({a: 42});
result = _(dictionary).chain().sortBy<TResult>();
result = _(dictionary).chain().sortBy<TResult, number>(dictionaryIterator);
result = _(dictionary).chain().sortBy<TResult, number>(dictionaryIterator, any);
result = _(dictionary).chain().sortBy<TResult>('');
result = _(dictionary).chain().sortBy<{a: number}, TResult>({a: 42});
}
}
result = <IStoogesAge[]>_.sortByAll(stoogesAges, function(stooge) { return Math.sin(stooge.age); }, function(stooge) { return stooge.name.slice(1); });
result = <IStoogesAge[]>_.sortByAll(stoogesAges, ['name', 'age']);
@@ -2982,9 +3054,6 @@ result = <IStoogesAge[]>_.sortByOrder(stoogesAges, [function(stooge) { return Ma
result = <IStoogesAge[]>_.sortByOrder(stoogesAges, ['name', 'age'], [true, false]);
result = <IStoogesAge[]>_.sortByOrder(stoogesAges, ['name', function(stooge) { return Math.sin(stooge.age); }], [true, false]);
result = <number[]>_([1, 2, 3]).sortBy(function (num) { return Math.sin(num); }).value();
result = <number[]>_([1, 2, 3]).sortBy(function (num) { return this.sin(num); }, Math).value();
result = <string[]>_(['banana', 'strawberry', 'apple']).sortBy('length').value();
result = <IFoodOrganic[]>_(foodsOrganic).sortByAll('organic', (food) => food.name, { organic: true }).value();
result = <IStoogesCombined[]>_.where(stoogesCombined, { 'age': 40 });
+160 -87
View File
@@ -6247,104 +6247,162 @@ declare module _ {
//_.sortBy
interface LoDashStatic {
/**
* Creates an array of elements, sorted in ascending order by the results of running each
* element in a collection through the callback. This method performs a stable sort, that
* is, it will preserve the original sort order of equal elements. 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 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 an 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 callback The function called per iteration.
* @param thisArg The this binding of callback.
* @return A new array of sorted elements.
**/
sortBy<T, TSort>(
collection: Array<T>,
iteratee?: ListIterator<T, TSort>,
thisArg?: any): T[];
/**
* @see _.sortBy
**/
sortBy<T, TSort>(
collection: List<T>,
iteratee?: ListIterator<T, TSort>,
thisArg?: any): T[];
/**
* @see _.sortBy
* @param pluckValue _.pluck style callback
**/
sortBy<T>(
collection: Array<T>,
pluckValue: string): T[];
/**
* @see _.sortBy
* @param pluckValue _.pluck style callback
**/
sortBy<T>(
collection: List<T>,
pluckValue: string): T[];
/**
* @see _.sortBy
* @param whereValue _.where style callback
**/
sortBy<W, T>(
collection: Array<T>,
whereValue: W): T[];
/**
* @see _.sortBy
* @param whereValue _.where style callback
**/
sortBy<W, T>(
collection: List<T>,
whereValue: W): T[];
/**
* Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts
* @param args The rules by which to sort
* Creates an array of elements, sorted in ascending order by the results of running each element in a
* collection through iteratee. This method performs a stable sort, that is, it preserves the original sort
* order of equal elements. 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
* valueof 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 new sorted array.
*/
sortByAll<T>(
collection: (Array<T>|List<T>),
...args: (ListIterator<T, boolean>|Object|string)[]
sortBy<T, TSort>(
collection: List<T>,
iteratee?: ListIterator<T, TSort>,
thisArg?: any
): T[];
/**
* @see _.sortBy
*/
sortBy<T, TSort>(
collection: Dictionary<T>,
iteratee?: DictionaryIterator<T, TSort>,
thisArg?: any
): T[];
/**
* @see _.sortBy
*/
sortBy<T>(
collection: List<T>|Dictionary<T>,
iteratee: string
): T[];
/**
* @see _.sortBy
*/
sortBy<W extends {}, T>(
collection: List<T>|Dictionary<T>,
whereValue: W
): T[];
/**
* @see _.sortBy
*/
sortBy<T>(
collection: List<T>|Dictionary<T>
): T[];
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.sortBy
**/
* @see _.sortBy
*/
sortBy<TSort>(
iteratee?: ListIterator<T, TSort>,
thisArg?: any): LoDashImplicitArrayWrapper<T>;
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortBy
* @param pluckValue _.pluck style callback
**/
sortBy(pluckValue: string): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortBy
* @param whereValue _.where style callback
**/
sortBy<W>(whereValue: W): LoDashImplicitArrayWrapper<T>;
/**
* Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts
* @param args The rules by which to sort
* @see _.sortBy
*/
sortByAll(...args: (ListIterator<T, boolean>|Object|string)[]): LoDashImplicitArrayWrapper<T>;
sortBy(iteratee: string): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<W extends {}>(whereValue: W): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy(): LoDashImplicitArrayWrapper<T>;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.sortBy
*/
sortBy<T, TSort>(
iteratee?: ListIterator<T, TSort>|DictionaryIterator<T, TSort>,
thisArg?: any
): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<T>(iteratee: string): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<W extends {}, T>(whereValue: W): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<T>(): LoDashImplicitArrayWrapper<T>;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.sortBy
*/
sortBy<TSort>(
iteratee?: ListIterator<T, TSort>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy(iteratee: string): LoDashExplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<W extends {}>(whereValue: W): LoDashExplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy(): LoDashExplicitArrayWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.sortBy
*/
sortBy<T, TSort>(
iteratee?: ListIterator<T, TSort>|DictionaryIterator<T, TSort>,
thisArg?: any
): LoDashExplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<T>(iteratee: string): LoDashExplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<W extends {}, T>(whereValue: W): LoDashExplicitArrayWrapper<T>;
/**
* @see _.sortBy
*/
sortBy<T>(): LoDashExplicitArrayWrapper<T>;
}
//_.sortByAll
@@ -6391,9 +6449,24 @@ declare module _ {
sortByAll<T>(
collection: List<T>,
...iteratees: (ListIterator<T, any>|string|Object)[]): T[];
/**
* Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts
* @param args The rules by which to sort
*/
sortByAll<T>(
collection: (Array<T>|List<T>),
...args: (ListIterator<T, boolean>|Object|string)[]
): T[];
}
interface LoDashImplicitArrayWrapper<T> {
/**
* Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts
* @param args The rules by which to sort
*/
sortByAll(...args: (ListIterator<T, boolean>|Object|string)[]): LoDashImplicitArrayWrapper<T>;
/**
* @see _.sortByAll
**/