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