whereNotIndexed method

Iterable<T> whereNotIndexed(
  1. bool predicate(
    1. T element,
    2. int index
    )
)

Yields all elements of the iterable for which the predicate (including the element's index) returns false.

This function iterates over the elements of the iterable, along with their indices. For each element, it checks the given predicate function. If the predicate returns false, the element is yielded. It effectively filters out elements for which the predicate (considering the element and its index) returns true.

Parameters: predicate (Function(T element, int index)):

A function that takes an element and its index as input and returns a boolean. If it returns false, the element is included in the result.

Returns: Iterable

Example:

List<int> numbers = [1, 2, 3, 4, 5];
Iterable<int> nonEvenIndexedNumbers = numbers.whereNotIndexed((n, index) => index % 2 == 0); // Yields [2, 4]

Note: The returned iterable is lazy. Elements are only processed when they are iterated over. This makes the function efficient for large iterables or when the full list of filtered elements is not needed all at once.

Implementation

Iterable<T> whereNotIndexed(bool predicate(T element, int index)) sync* {
  var index = 0;
  for (var element in this) {
    if (!predicate(element, index++)) {
      yield element;
    }
  }
}