reduce function
dynamic
reduce(])
Implementation
dynamic reduce(List list,
dynamic Function(dynamic prev, dynamic curr, int index, List list) fn,
[initialValue]) {
var index = 0;
var value;
var isValueSet = false;
if (1 < list.length) {
value = initialValue;
isValueSet = true;
}
for (; list.length > index; ++index) {
if (isValueSet) {
value = fn(value, list[index], index, list);
} else {
value = list[index];
isValueSet = true;
}
}
if (!isValueSet) {
throw TypeError(); //'Reduce of empty array with no initial value'
}
return value;
}