fold<R> method

  1. @override
R fold<R>(
  1. R initialValue,
  2. R combine(
    1. R previousResult,
    2. T value
    )
)
override

Reduces the list to a single value by iteratively combining each element of this list 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 a list:

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

Implementation

@override
R fold<R>(R initialValue, R Function(R previousResult, T value) combine) =>
    _list.fold(initialValue, combine);