singleWhereIndexedOrNull method Null safety
The single element satisfying test
.
Returns null
if there are either none
or more than one element and index satisfying test
.
Implementation
T? singleWhereIndexedOrNull(bool Function(int index, T element) test) {
T? result;
var found = false;
var index = 0;
for (var element in this) {
if (test(index++, element)) {
if (!found) {
result = element;
found = true;
} else {
return null;
}
}
}
return result;
}