dynamic fold(
initialValue,
dynamic combine(previousValue, E element)
)

Reduces a collection to a single value by iteratively combining each element of the collection with an existing value

Uses initialValue as the initial value, then iterates through the elements and updates the value with each element using the combine function, as if by:

var value = initialValue;
for (E element in this) {
  value = combine(value, element);
}
return value;

Example of calculating the sum of an iterable:

iterable.fold(0, (prev, element) => prev + element);

Source

/**
 * Reduces a collection to a single value by iteratively combining each
 * element of the collection with an existing value
 *
 * Uses [initialValue] as the initial value,
 * then iterates through the elements and updates the value with
 * each element using the [combine] function, as if by:
 *
 *     var value = initialValue;
 *     for (E element in this) {
 *       value = combine(value, element);
 *     }
 *     return value;
 *
 * Example of calculating the sum of an iterable:
 *
 *     iterable.fold(0, (prev, element) => prev + element);
 *
 */
dynamic fold(var initialValue,
             dynamic combine(var previousValue, E element));