IterableModifier<E> extension
Extension providing null-safe utility methods for iterables.
Adds convenience methods to all Iterable types for common operations
that may not find matching elements, returning null instead of throwing
exceptions.
This extension is particularly useful when searching collections where the element may not exist, avoiding the need for try-catch blocks or pre-checking with any.
Example:
final depots = [depot1, depot2, depot3];
final depot = depots.firstWhereOrNull((d) => d.code == 'D001');
if (depot != null) {
// Use depot
} else {
// Handle not found case
}
- on
-
- Iterable<
E>
- Iterable<
Methods
-
firstWhereOrNull(
bool test(E)) → E? -
Available on Iterable<
The first element satisfyingE> , provided by the IterableModifier extensiontest, ornullif none match.