firstWhereOrNull method

T? firstWhereOrNull(
  1. bool predicate(
    1. T
    )
)

Returns the first element satisfying predicate, or null if none found.

[1, 2, 3].firstWhereOrNull((e) => e > 5) // null

Implementation

T? firstWhereOrNull(bool Function(T) predicate) {
  for (final e in this) {
    if (predicate(e)) return e;
  }
  return null;
}