public static <S, E> E apply(final Traverser.Admin<S> traverser, final Traversal.Admin<S, E> traversal) {
        final Traverser<S> split = prepare(traverser, traversal);
        try {
            return traversal.next(); // map
        } catch (final NoSuchElementException e) {
            final String clazzOfTraverserValue = null == split.get() ? "null" : split.get().getClass().getSimpleName();
            throw new IllegalArgumentException(String.format("The provided traverser does not map to a value: %s[%s]->%s[%s] parent[%s]",
                    split, clazzOfTraverserValue, traversal, traversal.getClass().getSimpleName(), traversal.getParent().asStep().getTraversal()));
        } finally {
            //Close the traversal to release any underlying resources.
            CloseableIterator.closeIterator(traversal);
        }
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalUtil.java