blob: 04e924b93447527ac537f74f73b4a2a7e3721839 [file] [log] [blame]
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart=2.9
extension SafeAccess<T> on Iterable<T> {
T get safeFirst {
return isNotEmpty ? first : null;
}
}
main() {}
void test() {
final list = [];
list.safeFirst();
final list2 = <void Function(int)>[];
list2.safeFirst(0);
}
void errors() {
final list = <Object>[];
list.safeFirst();
final list2 = <void Function(int)>[];
list2.safeFirst();
}