copyWithReplaceWhere method

List<E> copyWithReplaceWhere(
  1. TestPredicate<E> test,
  2. E replacement
)

Copy current list, replacing elements of list that satisfy test predicate with replacement.

If no elements that satisfy test predicate found than just copy will be returned. If current list is null - returns new empty list.

Implementation

List<E> copyWithReplaceWhere(TestPredicate<E> test, E replacement) {
  return [for (final e in this) test(e) ? replacement : e];
}