firstWhereOrNull method
Returns the first element satisfying test
, or null
if none are found.
Implementation
T? firstWhereOrNull(bool Function(T element) test) => switch (this) {
[] => null, // Empty list case
[var first, ...] when test(first) => first, // First element matches
[_, ...var rest] =>
rest.firstWhereOrNull(test), // Check rest of the list
};