@Override
    protected S map(final Traverser.Admin<S> traverser) {
        // We may consider optimizing the iteration of these containers using subtype-specific interfaces.  For
        // example, we could use descendingIterator if we have a Deque.  But in general, we cannot reliably iterate a
        // collection in reverse, so we use the range algorithm with dynamically computed boundaries.
        final S start = traverser.get();
        final long high =
                start instanceof Map ? ((Map) start).size() :
                        start instanceof Collection ? ((Collection) start).size() :
                                start instanceof Path ? ((Path) start).size() :
                                        start instanceof Iterable ? IteratorUtils.count((Iterable) start) :
                                                IteratorUtils.count(IteratorUtils.asIterator(start));
        final long low = high - this.limit.get();
        final S result = RangeLocalStep.applyRange(start, low, high);
        return result;
    }
@author Matt Frantz (http://github.com/mhfrantz)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/TailLocalStep.java