Iterator
An iterator is an object that enables a programmer to traverse a sequence of elements, one at a time, without exposing the underlying structure. In common usage, an iterable is a collection or generator that can produce an iterator. An iterator maintains internal state about the current position and advances to the next element upon request.
Most languages separate the notions of iterable and iterator. An iterator exposes a method to return the
Iterators enable lazy evaluation: elements are produced on demand, which makes them suitable for large or infinite
Common considerations: most iterators are single-pass; restarting requires acquiring a new iterator. Iteration may have side
Applications include traversing lists, files, streams, or any data source that can be consumed sequentially. Iterators