Description
This issue was originally filed by @seaneagan
see http://en.wikipedia.org/wiki/Fold_(higher-order_function)
As with the other higher-order Collection methods, would be good to be consistent with JavaScript method names, and JavaScript has Array#reduce.
Similar to Collection#map (issue #945), this really wants to be a generic method (issue #254). The contract of this method could be something like:
R reduce<R>(R callback(R prev, E curr), [R initial = _somePrivateValue]) {
Iterator iter = iterator();
if(initial === _somePrivateValue) { // initial value not passed
if(!iter.hasNext()) return null; // no items either
initial = iter.next(); // defaults to first item
}
R prev = initial;
while(iter.hasNext()) prev = callback(prev, iter.next());
return prev;
}