The Iterator Pattern allows sequential access to the elements of an aggregate object without exposing its underlying representation.
Groovy has the iterator pattern built right in to many of its closure operators, e.g.
eachWithIndex as well as the
for .. in loop.
Results in the output:
There are also special iterator patterns built-in to other operators such as the
eachMatch operators for working with streams, files and regular expressions matches.