Skip to content

Commit cacc617

Browse files
committed
Simplify reduceRight() method.
1 parent 8e74a3a commit cacc617

File tree

1 file changed

+1
-9
lines changed
  • src/main/java/com/github/underscore

1 file changed

+1
-9
lines changed

src/main/java/com/github/underscore/$.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,7 @@ public static <T, E> E inject(final Iterable<T> iterable, final FunctionAccum<E,
237237
}
238238

239239
public static <T, E> E reduceRight(final Iterable<T> iterable, final FunctionAccum<E, T> func, final E zeroElem) {
240-
final List<T> list = newArrayList();
241-
for (T elem : iterable) {
242-
list.add(0, elem);
243-
}
244-
E accum = zeroElem;
245-
for (T element : list) {
246-
accum = func.apply(accum, element);
247-
}
248-
return accum;
240+
return reduce(reverse(iterable), func, zeroElem);
249241
}
250242

251243
public static <T, E> E foldr(final Iterable<T> iterable, final FunctionAccum<E, T> func, final E zeroElem) {

0 commit comments

Comments
 (0)