copyWithReplace method
Copy current list, replacing all element
occurrences with replacement
.
If element
is not in the list than just copy will be returned.
If current list is null
- returns new empty list.
Implementation
List<E> copyWithReplace(E element, E replacement) {
return [for (final e in this) e == element ? replacement : e];
}