Skip to content
Latchkey

What Is an Iterator Protocol?

An iterator protocol is the agreed interface that lets code step through a collection one element at a time without knowing its internal structure. A type that implements it provides a way to produce successive elements and to signal when there are no more. Language loop constructs are usually built on top of this protocol.

Why it matters

A shared iteration interface lets the same loops and algorithms work over lists, trees, streams, and generators alike. It decouples how data is stored from how it is traversed.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →