@Override
            public void apply(Sink sink, AbstractCodeWriter<?> writer) throws IOException {
                Object value = writer.getContext(variable());
                Iterator<? extends Map.Entry<?, ?>> iterator = getValueIterator(value);
                boolean isFirst = true;
                while (iterator.hasNext()) {
                    Map.Entry<?, ?> current = iterator.next();
                    writer.pushState();
                    writer.putContext(keyName, current.getKey());
                    writer.putContext(valueName, current.getValue());
                    writer.putContext(keyName + ".first", isFirst);
                    writer.putContext(keyName + ".last", !iterator.hasNext());
                    super.apply(sink, writer);
                    writer.popState();
                    isFirst = false;
                }
            }
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