Behavioral

Iterator

Provides sequential access to elements without exposing underlying structure.

Collection traversalCustom iteratorsStreaming data

Understanding Iterator

The Iterator pattern provides a way to access elements of a collection sequentially without exposing its underlying representation. Go's range keyword is a built-in iterator.

How It Works

Collection
A
B
C
D
E
Iterator
index: 0
Internal structure hidden
1

Collection

A collection of elements with internal structure.

1 / 4

Basic Implementation

Simple number collection iterator:

main.go
Loading editor...

Real-World Example: User Collection

User collection with filtering iterators:

main.go
Loading editor...