Muundo wa Iterator unatoa njia ya kupitia mkusanyo kwa kufuata mlolongo bila kufichua muundo wake wa ndani. Ni muhimu sana hivi kwamba imejenga ndani ya lugha nyingi za kisasa (for-of loops, iterators, generators).
Kile ambacho muundo wa Iterator kinachofanya
ITERATOR → access elements of a collection SEQUENTIALLY without exposing its internals:
→ provides a standard way to traverse (next element, has more?)
→ the collection's internal structure (array, tree, linked list) is HIDDEN
→ decouples traversal logic from the collection
→ "iterate without caring how the collection is structured"
