replaceWhere method

void replaceWhere(
  1. bool condition(
    1. T item
    ),
  2. T replace(
    1. T item
    ), {
  3. int count = -1,
})

Replaces items from current list, checked by condition and replaced by replace.

Implementation

void replaceWhere(bool Function(T item) condition, T Function(T item) replace, {int count = -1}) {
  var replaced = 0;
  for (var i = 0; i < length; i++) {
    if (condition(this[i])) {
      this[i] = replace(this[i]);
      replaced++;
      if (count >= 1 && replaced >= count) {
        return; // given count is valid && replaced count reaches limit
      }
    }
  }
}