The iterator pattern in Go
This is a continuation of the common design patterns I found in my old code series, which I started in a previous post.
The iterator pattern is a frequently used design pattern in software and it’s very simple. It entails that a collection must provide an iterator that can be used to iterate through its objects.
To put it in simple terms:
c := MyCollection{}
for c.Next() {
v := c.Value()
...
}Though, I haven’t seen this used very often in Go (it doesn’t mean it’s true). I could only find a single instance of this while going through my code (a Firestore DocumentIterator).