Documentation of the iteration interface is confusing


The docs list two methods as required: iterate(iter) and iterate(iter, state).

Later, in the first example, only one function is defined.
At least for a beginner, that’s confusing.


Note that

Base.iterate(S::Squares, state=1) = state > S.count ? nothing : (state*state, state+1)

defines two methods.

Base.iterate(S::Squares) and Base.iterate(S::Squares, state)

But it might be worth being more explicit.


Yep, the distinction between functions and methods in Julia can be confusing for beginners, esp. in cases such as this one where some methods are created implicitly.
Also confusing the issue might be that the distinction is different than the one made in OO languages
(i.e. methods belonging to classes).