diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 39e2ad335..0038741ee 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -699,6 +699,18 @@ result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) return key.charAt(0) != '_'; }); +result = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function(result, num) { + num *= num; + if (num % 2) { + return result.push(num) < 3; + } +}); +// → [1, 9, 25] + +result = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) { + result[key] = num * 3; +}); + //////////////////////////////////////////////////////////////////////////////////////// //WHAT'S LEFT //////////////////////////////////////////////////////////////////////////////////////// diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 347cbe8df..76f2ff2a1 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2678,7 +2678,23 @@ declare module _ { callback: ObjectIterator, thisArg?: any): any; - + /** + * An alternative to _.reduce this method transforms object to a new accumulator object which is + * the result of running each of its elements through a callback, with each callback execution + * potentially mutating the accumulator object. The callback is bound to thisArg and invoked with + * four arguments; (accumulator, value, key, object). Callbacks may exit iteration early by + * explicitly returning false. + * @param collection The collection to iterate over. + * @param callback The function called per iteration. + * @param accumulator The custom accumulator value. + * @param thisArg The this binding of callback. + * @return The accumulated value. + **/ + export function transform( + collection: Collection, + callback?: MemoIterator, + accumulator?: any, + thisArg?: any): any