replaceAllList<T> function
Delete all occurrences, or replace with to
.
Implementation
List<T> replaceAllList<T>(Iterable<T> it, T from, [T? to]) {
if (it.isEmpty) {
return [];
}
List<T> result = List.from(it);
List<int> indicesToReplace = [];
for (int i in nums(result.length)) {
if (deepEquals(result[i], from)) {
indicesToReplace.add(i);
}
}
for (int i in backwardsList(indicesToReplace)) {
to == null ? result.removeAt(i) : result[i] = to;
}
return result;
}