http://www.perlmonks.org?node_id=543899


in reply to How To: Make An Iterator

Under Things To Consider:
* The return value indicating exhaustion is important

After choosing a value that is known not to be valid in the list, document it. Allow the user to define their own if it is not possible to know in advance.
An even better approach is to use the iterator in list context and just return an empty list when the list is exhausted.
while (my ($elem) = $iter->()) { ... }
That way you don't need any assumptions, you don't need to make any limitations to the value space of the list, and it'll be easier for the maintainer that doesn't have to remember which list doesn't allow which element and which list uses what to signal list exhaustion.