From fdd3bcba57939ab170d88fbe0feec934cf822b72 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 19:24:39 -0400 Subject: [PATCH] _.reduceRight/_.foldr --- lodash/lodash-tests.ts | 4 ++++ lodash/lodash.d.ts | 49 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 16ce18ecf..f1fa2c014 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -303,6 +303,10 @@ result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) { return result; }, {}); +result = _.reduceRight([[0, 1], [2, 3], [4, 5]], function(a, b) { return a.concat(b); }, []); + + result = _.foldr([[0, 1], [2, 3], [4, 5]], function(a, b) { return a.concat(b); }, []); + 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 0a9d1e321..fc431ae37 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1283,6 +1283,30 @@ declare module _ { accumulator?: TResult, thisArg?: any): TResult; + /** + * This method is like _.reduce except that it iterates over elements of a collection from + * right to left. + * @param collection The collection to iterate over. + * @param callback The function called per iteration. + * @param accumulator Initial value of the accumulator. + * @param thisArg The this binding of callback. + * @return The accumulated value. + **/ + export function reduceRight( + collection: Collection, + callback: MemoIterator, + accumulator?: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + export function foldr( + collection: Collection, + callback: MemoIterator, + accumulator?: TResult, + thisArg?: any): 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. @@ -1367,30 +1391,7 @@ declare module _ { - /** - * The right-associative version of reduce. Delegates to the JavaScript 1.8 version of - * reduceRight, if it exists. Foldr is not as useful in JavaScript as it would be in a - * language with lazy evaluation. - * @param list Reduces the elements of this array. - * @param iterator Reduce iterator function for each element in `list`. - * @param memo Initial reduce state. - * @param context `this` object in `iterator`, optional. - * @return Reduced object result. - **/ - export function reduceRight( - list: Collection, - iterator: MemoIterator, - memo?: TResult, - context?: any): TResult; - - /** - * @see _.reduceRight - **/ - export function foldr( - list: Collection, - iterator: MemoIterator, - memo?: TResult, - context?: any): TResult; +