whereNotToIndexed method

void whereNotToIndexed(
  1. List<T> destination,
  2. bool predicate(
    1. T element,
    2. int index
    )
)

Appends all elements not matching the given predicate (which includes the element's index) to the given destination.

Iterates over the elements of the iterable, alongside their indices. For each element, checks the predicate function, which includes the element and its index. If the predicate returns false, the element is added to the destination list. This method is the inverse of a filtered indexed collection operation, where elements that do not satisfy the predicate are collected.

Parameters: destination (List

Example:

List<String> words = ['apple', 'banana', 'cherry', 'date'];
List<String> nonCherryWords = [];
words.whereNotToIndexed(nonCherryWords, (word, index) => word == 'cherry' && index == 2);
// nonCherryWords now contains ['apple', 'banana', 'date']

Note: The function modifies the destination list in place by adding elements to it. Ensure that the destination list is modifiable and initialized.

Implementation

void whereNotToIndexed(List<T> destination, bool predicate(T element, int index)) {
  var index = 0;
  for (var element in this) {
    if (!predicate(element, index++)) {
      destination.add(element);
    }
  }
}