fold method

T fold<T>(T initialValue, T combine(T previousValue, String 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

T fold<T>(T initialValue, T combine(T previousValue, String element)) {
  return readClasses().fold<T>(initialValue, combine);
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-svg/AttributeClassSet/fold.html