Iterators
An iterator is an object that yields elements of a sequence one at a time. An iterable is an object that can produce an iterator. The iterator maintains internal state and, on each request, returns the next element until the sequence is exhausted. Once exhausted, subsequent requests are handled differently depending on the language, such as signaling termination or raising a specific exception.
In many languages, the interface and conventions differ. Python, for example, uses an iterator protocol where
Key features of iterators include lazy evaluation, meaning elements are produced only as needed, and memory
Common caveats include that many iterators are single-pass: once exhausted, they may not be reset without recreating