_.reduceRight/_.foldr

This commit is contained in:
Brian Zengel
2013-10-18 19:24:39 -04:00
parent 37d2cb3292
commit fdd3bcba57
2 changed files with 29 additions and 24 deletions
+4
View File
@@ -303,6 +303,10 @@ result = <any>_.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) {
return result;
}, {});
result = <any>_.reduceRight([[0, 1], [2, 3], [4, 5]], function(a, b) { return a.concat(b); }, []);
result = <any>_.foldr([[0, 1], [2, 3], [4, 5]], function(a, b) { return a.concat(b); }, []);
result = <boolean>_.some([null, 0, 'yes', false], Boolean);
result = <boolean>_.some(foodsCombined, 'organic');
result = <boolean>_.some(foodsCombined, { 'type': 'meat' });
+25 -24
View File
@@ -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<T, TResult>(
collection: Collection<T>,
callback: MemoIterator<T, TResult>,
accumulator?: TResult,
thisArg?: any): TResult;
/**
* @see _.reduceRight
**/
export function foldr<T, TResult>(
collection: Collection<T>,
callback: MemoIterator<T, TResult>,
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<T, TResult>(
list: Collection<T>,
iterator: MemoIterator<T, TResult>,
memo?: TResult,
context?: any): TResult;
/**
* @see _.reduceRight
**/
export function foldr<T, TResult>(
list: Collection<T>,
iterator: MemoIterator<T, TResult>,
memo?: TResult,
context?: any): TResult;