in reply to How To: Make An Iterator
Under Things To Consider:
* The return value indicating exhaustion is importantAn even better approach is to use the iterator in list context and just return an empty list when the list is exhausted.
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.
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.while (my ($elem) = $iter->()) { ... }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How To: Make An Iterator
by Limbic~Region (Chancellor) on Apr 17, 2006 at 22:42 UTC | |
by Anonymous Monk on Apr 20, 2006 at 00:09 UTC | |
by Limbic~Region (Chancellor) on Apr 20, 2006 at 12:24 UTC |
In Section
Tutorials