replaceWhere method
Replaces every element that matches the comparator
with newValue
.
Example:
[1, 2, 3].replaceWhere((n) => n < 3, 0); // [0, 0, 3]
Implementation
Iterable<T> replaceWhere(
bool Function(T currentValue) comparator, T newValue) sync* {
final it = iterator;
while (it.moveNext()) {
if (comparator(it.current)) {
yield newValue;
} else {
yield it.current;
}
}
}