summaryrefslogtreecommitdiff
path: root/lib/first_where_ext.dart
blob: a633b918f8c56408ea39bf8ae2e00329ab92c42f (plain)
1
2
3
4
5
6
7
8
9
10
extension FirstWhereExt<T> on Iterable<T> {
  /// The first element satisfying [test], or `null` if there are none.
  // firstWhereOrElse doesn't want to return null.
  T? firstWhereOrNull(bool Function(T element) test) {
    for (final element in this) {
      if (test(element)) return element;
    }
    return null;
  }
}