The Iterator Pattern in Michelson
Traversing immutable list collections iteratively through recursive smart contract calls.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Enchantment // Stackmancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MICHELSON PATTERN //
parameter (unit %next);
storage (pair (list int) (list int)); # Remaining items and Processed items
code {
DROP;
UNPAIR;
IF_CONS {
# Element is on stack, remaining list is below
# In this mock iterator, we just move it to processed
DIG 2;
SWAP;
CONS;
SWAP; PAIR;
NIL operation; PAIR
} {
PUSH string "IteratorExhausted"; FAILWITH;
}
}
Runic Tags:
#behavioral
#iterator
#stack-based smart contracts
#michelson
#tezos