whereNotNull method
Returns a new lazy Iterable containing all elements of this collection
that are not null.
This method filters the elements of the collection and includes only those
elements that are not null in the resulting iterable.
-
Returns: A new lazy Iterable containing all elements of this collection that are not
null. -
Example:
Iterable<String?> words = ['apple', null, 'banana', null, 'cherry']; Iterable<String> nonNullWords = words.whereNotNull(); print(nonNullWords); // Output: ['apple', 'banana', 'cherry']
Note:
This method creates a new lazy Iterable and does not modify the original
collection. It allows you to filter out null elements from the collection.
Implementation
Iterable<T> whereNotNull() => where((element) => element != null);