single method

Option<T> single()

Returns the single element of an iterator, None if this is empty or has more than one element.

Implementation

Option<T> single() {
  final firstTwo = _list.take(2).iterator;
  if (!firstTwo.moveNext()) {
    return None;
  }
  final first = firstTwo.current;
  if (!firstTwo.moveNext()) {
    return Some(first);
  }
  return None;
}