diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 945da750f..eb623a470 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -202,8 +202,8 @@ result = _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); * Collections * ************* */ -result = _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); -result = _.at(['moe', 'larry', 'curly'], 0, 2); +result = _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); +result = _.at(['moe', 'larry', 'curly'], 0, 2); result = _.every([true, 1, null, 'yes'], Boolean); result = _.every(stoogesAges, 'age'); @@ -213,6 +213,14 @@ result = _.every(stoogesAges, { 'age': 50 }); result = _.all(stoogesAges, 'age'); result = _.all(stoogesAges, { 'age': 50 }); +result = _.map([1, 2, 3], function(num) { return num * 3; }); +result = _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); +result = _.map(stoogesAges, 'name'); + + result = _.collect([1, 2, 3], function(num) { return num * 3; }); + result = _.collect({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); + result = _.collect(stoogesAges, 'name'); + result = _.some([null, 0, 'yes', false], Boolean); result = _.some(foodsCombined, 'organic'); result = _.some(foodsCombined, { 'type': 'meat' }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b41d54b4d..f48beecfc 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -846,6 +846,69 @@ declare module _ { collection: Collection, whereValue: Dictionary): boolean; + /** + * 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. + **/ + export function map( + collection: List, + callback: ListIterator, + 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. + **/ + export function map( + object: Dictionary, + callback: ObjectIterator, + thisArg?: any): TResult[]; + + /** + * @see _.map + * @param pluckValue _.pluck style callback + **/ + export function map( + collection: List, + pluckValue: string): TResult[]; + + /** + * @see _.map + **/ + export function collect( + collection: List, + callback: ListIterator, + thisArg?: any): TResult[]; + + /** + * @see _.map + **/ + export function collect( + object: Dictionary, + callback: ObjectIterator, + thisArg?: any): TResult[]; + + /** + * @see _.map + **/ + export function collect( + collection: List, + pluckValue: string): TResult[]; + /** * Checks if the callback returns a truey value for any element of a collection. The function * returns as soon as it finds a passing value and does not iterate over the entire collection. @@ -969,48 +1032,6 @@ declare module _ { iterator: ObjectIterator, context?: any): void; - /** - * Produces a new array of values by mapping each value in list through a transformation function - * (iterator). If the native map method exists, it will be used instead. If list is a JavaScript - * object, iterator's arguments will be (value, key, object). - * @param list Maps the elements of this array. - * @param iterator Map iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return The mapped array result. - **/ - export function map( - list: List, - iterator: ListIterator, - context?: any): TResult[]; - - /** - * @see _.map - * @param object Maps the properties of this object. - * @param iterator Map iterator function for each property on `obj`. - * @param context `this` object in `iterator`, optional. - * @return The mapped object result. - **/ - export function map( - object: Dictionary, - iterator: ObjectIterator, - context?: any): TResult[]; - - /** - * @see _.map - **/ - export function collect( - list: List, iterator: - ListIterator, - context?: any): TResult[]; - - /** - * @see _.map - **/ - export function collect( - object: Dictionary, - iterator: ObjectIterator, - context?: any): TResult[]; - /** * Also known as inject and foldl, reduce boils down a list of values into a single value. * Memo is the initial state of the reduction, and each successive step of it should be