whereNotTo method
Appends all elements not matching the given predicate to the given destination.
Iterates over the elements of the iterable and checks the predicate function for each element.
If the predicate returns false, the element is added to the destination list.
This is effectively the inverse of a filter operation, where elements that do not satisfy
the predicate are collected.
Parameters: destination (List
Example:
List<int> numbers = [1, 2, 3, 4, 5];
List<int> nonEvenNumbers = [];
numbers.whereNotTo(nonEvenNumbers, (n) => n % 2 == 0);
// nonEvenNumbers now contains [1, 3, 5]
Note:
The function modifies the destination list in place, adding elements to it.
Ensure that the destination list is modifiable and initialized.
Implementation
void whereNotTo(List<T> destination, bool predicate(T element)) {
for (var element in this) {
if (!predicate(element)) {
destination.add(element);
}
}
}