singleOrNull property

T? singleOrNull

The single element of this iterator, or null.

If the iterator has precisely one element, this is that element. Otherwise, if the iterator has zero elements, or it has two or more, the value is null.

Implementation

T? get singleOrNull {
  var iterator = this.iterator;
  if (iterator.moveNext()) {
    var result = iterator.current;
    if (!iterator.moveNext()) return result;
  }
  return null;
}