public static <T> Optional<T> findFirst(final Iterator<T> iterator) {
        try {
            if (iterator.hasNext()) {
                return Optional.ofNullable(iterator.next());
            }
            return Optional.empty();
        } finally {
            CloseableIterator.closeIterator(iterator);
        }
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java