The iterator design pattern

We use iterators in software projects all the time. When we traverse a list or go through the items of a set or a map, we use an iterator.

The iterator design pattern provides a way to access the elements of an aggregate object (collection) in a sequential manner without exposing the underlying representation of the items.

When using the iterator design pattern, the developer doesn't need to know whether there is a linked list, array, tree, or a hash map underneath.

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.