@Override
    protected E supply() {
        if (null == this.sideEffectCapableSteps) {
            this.sideEffectCapableSteps = new HashMap<>();
            Traversal.Admin<?, ?> parentTraversal = this.getTraversal();
            while (!(parentTraversal instanceof EmptyTraversal)) {
                for (final SideEffectCapable<Object, E> capableStep : TraversalHelper.getStepsOfAssignableClassRecursively(SideEffectCapable.class, parentTraversal)) {
                    if (this.sideEffectKeys.contains(capableStep.getSideEffectKey()) && !this.sideEffectCapableSteps.containsKey(capableStep.getSideEffectKey()))
                        this.sideEffectCapableSteps.put(capableStep.getSideEffectKey(), capableStep);
                }
                if (this.sideEffectKeys.size() == this.sideEffectCapableSteps.size())
                    break;
                parentTraversal = parentTraversal.getParent().asStep().getTraversal();
            }
        }
        ////////////
        if (this.sideEffectKeys.size() == 1) {
            final String sideEffectKey = this.sideEffectKeys.get(0);
            final E result = this.getTraversal().getSideEffects().<E>get(sideEffectKey);
            final SideEffectCapable<Object, E> sideEffectCapable = this.sideEffectCapableSteps.get(sideEffectKey);
            final E finalResult = null == sideEffectCapable ? result : sideEffectCapable.generateFinalResult(result);
            this.getTraversal().getSideEffects().set(sideEffectKey, finalResult);
            return finalResult;
        } else
            return (E) this.getMapOfSideEffects();
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java