replaceWhere method

bool replaceWhere(
  1. TestPredicate<E> test,
  2. E replacement
)

Replaces all elements of list that satisfy test predicate with replacement.

Returns true if at least one element was replaced. If no elements that satisfy test predicate found than will be no changes.

Implementation

bool replaceWhere(TestPredicate<E> test, E replacement) {
  var found = false;
  final len = length;
  for (var i = 0; i < len; i++) {
    if (test(this[i])) {
      this[i] = replacement;
      found = true;
    }
  }

  return found;
}