private static Iterator<? extends Map.Entry<?, ?>> getValueIterator(Object value) {
        if (value instanceof Map) {
            return ((Map<?, ?>) value).entrySet().iterator();
        } else if (value instanceof Iterable) {
            Iterator<?> iter = ((Iterable<?>) value).iterator();
            return new Iterator<Map.Entry<?, ?>>() {
                int position = 0;

                @Override
                public boolean hasNext() {
                    return iter.hasNext();
                }

                @Override
                public Map.Entry<?, ?> next() {
                    return Pair.of(position++, iter.next());
                }
            };
        } else {
            return Collections.emptyIterator();
        }
    }
A BlockOperation that repeats a template for each value referenced by the block. Each iteration pushes
a state to the writer that includes key, value, key.first, and key.last context properties. The name
of the context property can be customized in the template.
smithy-utils/src/main/java/software/amazon/smithy/utils/CodeFormatter.java