mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 06:50:19 +00:00
Merge pull request #6002 from chrootsu/lodash-map
lodash: changed _.map() method (alias _.collect())
This commit is contained in:
+96
-12
@@ -664,6 +664,51 @@ result = <number[]>_([1, 2]).zipWith<number>([1, 2], [1, 2], [1, 2], [1, 2], [1,
|
||||
result = _(testAtDictionary).at<TResult>(0, '1', [2], ['3'], [4, '5']).value();
|
||||
}
|
||||
|
||||
// _.collect
|
||||
module TestCollect {
|
||||
let array: number[];
|
||||
let list: _.List<number>;
|
||||
let dictionary: _.Dictionary<number>;
|
||||
let listIterator: {(value: number, index: number, collection: _.List<number>): TResult};
|
||||
let dictionaryIterator: {(value: number, key: string, collection: _.Dictionary<number>): TResult};
|
||||
{
|
||||
let result: TResult[];
|
||||
result = _.collect<number, TResult>(array);
|
||||
result = _.collect<number, TResult>(array, listIterator);
|
||||
result = _.collect<number, TResult>(array, listIterator, any);
|
||||
result = _.collect<number, TResult>(array, '');
|
||||
result = _.collect<number, TResult>(list);
|
||||
result = _.collect<number, TResult>(list, listIterator);
|
||||
result = _.collect<number, TResult>(list, listIterator, any);
|
||||
result = _.collect<number, TResult>(list, '');
|
||||
result = _.collect<number, TResult>(dictionary);
|
||||
result = _.collect<number, TResult>(dictionary, dictionaryIterator);
|
||||
result = _.collect<number, TResult>(dictionary, dictionaryIterator, any);
|
||||
result = _.collect<number, TResult>(dictionary, '');
|
||||
result = _<number>(array).collect<TResult>().value();
|
||||
result = _<number>(array).collect<TResult>(listIterator).value();
|
||||
result = _<number>(array).collect<TResult>(listIterator, any).value();
|
||||
result = _<number>(array).collect<TResult>('').value();
|
||||
result = _(list).collect<number, TResult>().value();
|
||||
result = _(list).collect<number, TResult>(listIterator).value();
|
||||
result = _(list).collect<number, TResult>(listIterator, any).value();
|
||||
result = _(list).collect<number, TResult>('').value();
|
||||
result = _(dictionary).collect<number, TResult>().value();
|
||||
result = _(dictionary).collect<number, TResult>(dictionaryIterator).value();
|
||||
result = _(dictionary).collect<number, TResult>(dictionaryIterator, any).value();
|
||||
result = _(dictionary).collect<number, TResult>('').value();
|
||||
}
|
||||
{
|
||||
let result: boolean[];
|
||||
result = _.collect<number, {}>(array, {});
|
||||
result = _.collect<number, {}>(list, {});
|
||||
result = _.collect<number, {}>(dictionary, {});
|
||||
result = _<number>(array).collect<{}>({}).value();
|
||||
result = _(list).collect<{}>({}).value();
|
||||
result = _(dictionary).collect<{}>({}).value();
|
||||
}
|
||||
}
|
||||
|
||||
result = <boolean>_.contains([1, 2, 3], 1);
|
||||
result = <boolean>_.contains([1, 2, 3], 1, 2);
|
||||
result = <boolean>_.contains({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40);
|
||||
@@ -809,21 +854,60 @@ result = <_.Dictionary<IKey>>_.indexBy(keys, function (key) { this.fromCharCode(
|
||||
result = <number[][]>_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
|
||||
result = <string[][]>_.invoke([123, 456], String.prototype.split, '');
|
||||
|
||||
result = <number[]>_.map([1, 2, 3], function (num) { return num * 3; });
|
||||
result = <number[]>_.map({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { return num * 3; });
|
||||
result = <IStoogesAge[]>_.map(stoogesAges, 'name');
|
||||
// _.map
|
||||
module TestMap {
|
||||
let array: number[];
|
||||
let list: _.List<number>;
|
||||
let dictionary: _.Dictionary<number>;
|
||||
|
||||
result = <number[]>_([1, 2, 3]).map(function (num) { return num * 3; }).value();
|
||||
result = <number[]>_({ 'one': 1, 'two': 2, 'three': 3 }).map(function (num: number) { return num * 3; }).value();
|
||||
result = <IStoogesAge[]>_(stoogesAges).map('name').value();
|
||||
let listIterator: (value: number, index: number, collection: _.List<number>) => TResult;
|
||||
let dictionaryIterator: (value: number, key: string, collection: _.Dictionary<number>) => TResult;
|
||||
|
||||
result = <number[]>_.collect([1, 2, 3], function (num) { return num * 3; });
|
||||
result = <number[]>_.collect({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { return num * 3; });
|
||||
result = <IStoogesAge[]>_.collect(stoogesAges, 'name');
|
||||
{
|
||||
let result: TResult[];
|
||||
|
||||
result = <number[]>_([1, 2, 3]).collect(function (num) { return num * 3; }).value();
|
||||
result = <number[]>_({ 'one': 1, 'two': 2, 'three': 3 }).collect(function (num: number) { return num * 3; }).value();
|
||||
result = <IStoogesAge[]>_(stoogesAges).collect('name').value();
|
||||
result = _.map<number, TResult>(array);
|
||||
result = _.map<number, TResult>(array, listIterator);
|
||||
result = _.map<number, TResult>(array, listIterator, any);
|
||||
result = _.map<number, TResult>(array, '');
|
||||
|
||||
result = _.map<number, TResult>(list);
|
||||
result = _.map<number, TResult>(list, listIterator);
|
||||
result = _.map<number, TResult>(list, listIterator, any);
|
||||
result = _.map<number, TResult>(list, '');
|
||||
|
||||
result = _.map<number, TResult>(dictionary);
|
||||
result = _.map<number, TResult>(dictionary, dictionaryIterator);
|
||||
result = _.map<number, TResult>(dictionary, dictionaryIterator, any);
|
||||
result = _.map<number, TResult>(dictionary, '');
|
||||
|
||||
result = _<number>(array).map<TResult>().value();
|
||||
result = _<number>(array).map<TResult>(listIterator).value();
|
||||
result = _<number>(array).map<TResult>(listIterator, any).value();
|
||||
result = _<number>(array).map<TResult>('').value();
|
||||
|
||||
result = _(list).map<number, TResult>().value();
|
||||
result = _(list).map<number, TResult>(listIterator).value();
|
||||
result = _(list).map<number, TResult>(listIterator, any).value();
|
||||
result = _(list).map<number, TResult>('').value();
|
||||
|
||||
result = _(dictionary).map<number, TResult>().value();
|
||||
result = _(dictionary).map<number, TResult>(dictionaryIterator).value();
|
||||
result = _(dictionary).map<number, TResult>(dictionaryIterator, any).value();
|
||||
result = _(dictionary).map<number, TResult>('').value();
|
||||
}
|
||||
{
|
||||
let result: boolean[];
|
||||
|
||||
result = _.map<number, {}>(array, {});
|
||||
result = _.map<number, {}>(list, {});
|
||||
result = _.map<number, {}>(dictionary, {});
|
||||
|
||||
result = _<number>(array).map<{}>({}).value();
|
||||
result = _(list).map<{}>({}).value();
|
||||
result = _(dictionary).map<{}>({}).value();
|
||||
}
|
||||
}
|
||||
|
||||
// _.ceil
|
||||
result = <number>_.ceil(4.006);
|
||||
|
||||
Vendored
+191
-106
@@ -2034,6 +2034,107 @@ declare module _ {
|
||||
at<TResult>(...props: Array<number|string|Array<number|string>>): LoDashArrayWrapper<TResult>;
|
||||
}
|
||||
|
||||
//_.collect
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<T, TResult>(
|
||||
collection: List<T>,
|
||||
iteratee?: ListIterator<T, TResult>,
|
||||
thisArg?: any
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<T extends {}, TResult>(
|
||||
collection: Dictionary<T>,
|
||||
iteratee?: DictionaryIterator<T, TResult>,
|
||||
thisArg?: any
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<T, TResult>(
|
||||
collection: List<T>,
|
||||
iteratee?: string
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<T, TResult>(
|
||||
collection: Dictionary<T>,
|
||||
iteratee?: string
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<T, TObject extends {}>(
|
||||
collection: List<T>,
|
||||
iteratee?: TObject
|
||||
): boolean[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<T, TObject extends {}>(
|
||||
collection: Dictionary<T>,
|
||||
iteratee?: TObject
|
||||
): boolean[];
|
||||
}
|
||||
|
||||
interface LoDashArrayWrapper<T> {
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<TResult>(
|
||||
iteratee?: ListIterator<T, TResult>,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<TResult>(
|
||||
iteratee?: string
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<TObject extends {}>(
|
||||
iteratee?: TObject
|
||||
): LoDashArrayWrapper<boolean>;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<TValue, TResult>(
|
||||
iteratee?: ListIterator<TValue, TResult>|DictionaryIterator<TValue, TResult>,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<TValue, TResult>(
|
||||
iteratee?: string
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
collect<TObject extends {}>(
|
||||
iteratee?: TObject
|
||||
): LoDashArrayWrapper<boolean>;
|
||||
}
|
||||
|
||||
//_.contains
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
@@ -3494,143 +3595,127 @@ declare module _ {
|
||||
//_.map
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates an array of values by running each element in the collection through 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 theArg The this binding of callback.
|
||||
* @return The mapped array result.
|
||||
**/
|
||||
map<T, TResult>(
|
||||
collection: Array<T>,
|
||||
callback: ListIterator<T, TResult>,
|
||||
thisArg?: any): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
* Creates an array of values by running each element in collection through 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.
|
||||
*
|
||||
* Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues,
|
||||
* _.reject, and _.some.
|
||||
*
|
||||
* The guarded methods are:
|
||||
* ary, callback, chunk, clone, create, curry, curryRight, drop, dropRight, every, fill, flatten, invert, max,
|
||||
* min, parseInt, slice, sortBy, take, takeRight, template, trim, trimLeft, trimRight, trunc, random, range,
|
||||
* sample, some, sum, uniq, and words
|
||||
*
|
||||
* @alias _.collect
|
||||
*
|
||||
* @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 mapped array.
|
||||
*/
|
||||
map<T, TResult>(
|
||||
collection: List<T>,
|
||||
callback: ListIterator<T, TResult>,
|
||||
thisArg?: any): TResult[];
|
||||
iteratee?: ListIterator<T, TResult>,
|
||||
thisArg?: any
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
* @param object The object to iterate over.
|
||||
* @param callback The function called per iteration.
|
||||
* @param thisArg `this` object in `iterator`, optional.
|
||||
* @return The mapped object result.
|
||||
**/
|
||||
* @see _.map
|
||||
*/
|
||||
map<T extends {}, TResult>(
|
||||
object: Dictionary<T>,
|
||||
callback: DictionaryIterator<T, TResult>,
|
||||
thisArg?: any): TResult[];
|
||||
collection: Dictionary<T>,
|
||||
iteratee?: DictionaryIterator<T, TResult>,
|
||||
thisArg?: any
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
map<T, TResult>(
|
||||
collection: Array<T>,
|
||||
pluckValue: string): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
* @see _.map
|
||||
*/
|
||||
map<T, TResult>(
|
||||
collection: List<T>,
|
||||
pluckValue: string): TResult[];
|
||||
iteratee?: string
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<T, TResult>(
|
||||
collection: Array<T>,
|
||||
callback: ListIterator<T, TResult>,
|
||||
thisArg?: any): TResult[];
|
||||
* @see _.map
|
||||
*/
|
||||
map<T, TResult>(
|
||||
collection: Dictionary<T>,
|
||||
iteratee?: string
|
||||
): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<T, TResult>(
|
||||
* @see _.map
|
||||
*/
|
||||
map<T, TObject extends {}>(
|
||||
collection: List<T>,
|
||||
callback: ListIterator<T, TResult>,
|
||||
thisArg?: any): TResult[];
|
||||
iteratee?: TObject
|
||||
): boolean[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<T extends {}, TResult>(
|
||||
object: Dictionary<T>,
|
||||
callback: DictionaryIterator<T, TResult>,
|
||||
thisArg?: any): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<T, TResult>(
|
||||
collection: Array<T>,
|
||||
pluckValue: string): TResult[];
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<T, TResult>(
|
||||
collection: List<T>,
|
||||
pluckValue: string): TResult[];
|
||||
* @see _.map
|
||||
*/
|
||||
map<T, TObject extends {}>(
|
||||
collection: Dictionary<T>,
|
||||
iteratee?: TObject
|
||||
): boolean[];
|
||||
}
|
||||
|
||||
interface LoDashArrayWrapper<T> {
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
* @see _.map
|
||||
*/
|
||||
map<TResult>(
|
||||
callback: ListIterator<T, TResult>,
|
||||
thisArg?: any): LoDashArrayWrapper<TResult>;
|
||||
iteratee?: ListIterator<T, TResult>,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
* @see _.map
|
||||
*/
|
||||
map<TResult>(
|
||||
pluckValue: string): LoDashArrayWrapper<TResult>;
|
||||
iteratee?: string
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<TResult>(
|
||||
callback: ListIterator<T, TResult>,
|
||||
thisArg?: any): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<TResult>(
|
||||
pluckValue: string): LoDashArrayWrapper<TResult>;
|
||||
* @see _.map
|
||||
*/
|
||||
map<TObject extends {}>(
|
||||
iteratee?: TObject
|
||||
): LoDashArrayWrapper<boolean>;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
map<T extends {}, TResult>(
|
||||
callback: ObjectIterator<T, TResult>,
|
||||
thisArg?: any): LoDashArrayWrapper<TResult>;
|
||||
* @see _.map
|
||||
*/
|
||||
map<TValue, TResult>(
|
||||
iteratee?: ListIterator<TValue, TResult>|DictionaryIterator<TValue, TResult>,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
**/
|
||||
collect<T extends {}, TResult>(
|
||||
callback: ObjectIterator<T, TResult>,
|
||||
thisArg?: any): LoDashArrayWrapper<TResult>;
|
||||
* @see _.map
|
||||
*/
|
||||
map<TValue, TResult>(
|
||||
iteratee?: string
|
||||
): LoDashArrayWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.map
|
||||
*/
|
||||
map<TObject extends {}>(
|
||||
iteratee?: TObject
|
||||
): LoDashArrayWrapper<boolean>;
|
||||
}
|
||||
|
||||
//_.ceil
|
||||
@@ -8574,7 +8659,7 @@ declare module _ {
|
||||
}
|
||||
|
||||
interface ListIterator<T, TResult> {
|
||||
(value: T, index: number, collection: T[]): TResult;
|
||||
(value: T, index: number, collection: List<T>): TResult;
|
||||
}
|
||||
|
||||
interface DictionaryIterator<T, TResult> {
|
||||
|
||||
Reference in New Issue
Block a user