singleOrNull property

T? singleOrNull

The single element of the iterable, or null.

The value is null if the iterable is empty or it contains more than one element.

Implementation

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