singleWhereOrNull method
Returns the single element matching test, or null if zero or more than one match.
Implementation
T? singleWhereOrNull(bool Function(T element) test) {
T? result;
var matchCount = 0;
for (final element in this) {
if (test(element)) {
matchCount++;
if (matchCount > 1) return null;
result = element;
}
}
return matchCount == 1 ? result : null;
}