exceptElement method

Iterable<T> exceptElement(
  1. T element
)

Yields elements from this iterable that are not equal to the specified element.

Iterates over each element in the current iterable. If an element is not equal to the provided element, it is yielded.

Parameters: element (T): An element to be excluded from the resulting iterable.

Returns: Iterable

Example:

List<int> numbers = [1, 2, 3, 4, 5];
Iterable<int> result = numbers.exceptElement(3); // Yields [1, 2, 4, 5]

Note: The returned iterable is lazy. Elements are only processed when they are iterated over.

Implementation

Iterable<T> exceptElement(T element) sync* {
  for (var current in this) {
    if (element != current) {
      yield current;
    }
  }
}