Yields the only element if found, nothing otherwise.

@param <E> the iterable element type
@param iterable the iterable that will be consumed
@throws IllegalStateException if the iterator contains more than one
element
@return just the element or nothing
556998
public static <E> Optional<E> maybeOne(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call maybeOne with a null iterable");
        return new MaybeOneElement<E>().apply(iterable.iterator());
    }
1255003
public static <T> Iterable<T> nullSafeIterable(T[] iterable) {
        return (iterable != null) ? Arrays.asList(iterable) : Collections.EMPTY_LIST;
    }
768088
public static <E> long count(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call count with a null iterable");
        return count(iterable.iterator());
    }
231584
public String format(Iterable<?> iterable) {
    if (iterable == null) {
      return StringUtils.EMPTY;
    }
    return format(iterable.iterator());
  }
67795
public static <T> Expiring<T> of(Iterable<T> iterable) {
		return of(checkNotNull(iterable).iterator());
	}
417297
@NullSafe
  @Override
  public Iterator<VALUE> iterator() {
    return Collections.unmodifiableMap(this.map).values().iterator();
  }
1112506
private @Nonnull Optional<XQuery> findElement(Function<Node, Node> iterator) {
        Node it = node;
        do {
            it = iterator.apply(it);
        } while (it != null && !(it instanceof Element));
        return Optional.ofNullable(it).map(XQuery::new);
    }
157848
public static <E> E last(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call last with a null iterable");
        return new LastElement<E>().apply(iterable.iterator());
    }
1232801
public static <E> Optional<E> maybeOne(Iterator<E> iterator) {
        return new MaybeOneElement<E>().apply(iterator);
    }
833364
public static <T> CloseableIterable<T> fromIterable(Iterable<T> iterable) {
        requireNonNull(iterable);
        if (iterable instanceof CloseableIterable) return (CloseableIterable<T>) iterable;

        return new FluentCloseableIterable<T>() {
            @Override
            protected void doClose() {
                if (iterable instanceof AutoCloseable) {
                    try {
                        ((AutoCloseable) iterable).close();
                    } catch (RuntimeException re) {
                        throw re;
                    } catch (Exception e) {
                        throw new IllegalStateException(e);
                    }
                }
            }

            @Override
            protected Iterator<T> retrieveIterator() {
                return iterable.iterator();
            }
        };
    }
1218321
public static <T> LazyIterable<T> reject(Iterable<T> iterable, Predicate<? super T> predicate)
    {
        return new RejectIterable<T>(iterable, predicate);
    }
899680
public static <T> Iterable<T> distinct(final Iterable<T> iterable) {
        requireNonNull(iterable);
        return () -> Iterators2.distinct(iterable.iterator());
    }
544769
public static <E> Optional<E> find(final Iterable<E> iterable, final Predicate<E> pred) {
        for (E element : iterable) {
            if (pred.test(element)) {
                return Optional.of(element);
            }
        }
        return Optional.absent();
    }
544589
public static <E> SynchronizedRichIterable<E> of(RichIterable<E> iterable)
    {
        return new SynchronizedRichIterable<E>(iterable);
    }
947864
public static <E> Iterable<E> asIterable(final Iterator<E> iter) {
		return new Iterable<E>() {
			@Override
			public Iterator<E> iterator() {
				return iter;
			}
		};
	}
701365
public static <T> Iterable<T> cast(Iterable<?> iterable) {
    return iterable == null ? null : new CastingIterable<T>(iterable);
  }
1277389
def assert_single_element(iterable):
  
  it = iter(iterable)
  first_item = next(it)

  try:
    next(it)
  except StopIteration:
    return first_item

  raise ValueError("iterable {!r} has more than one element.".format(iterable))