[fpc-devel] for-in-index loop
Graeme Geldenhuys
graeme at geldenhuys.co.uk
Fri Jan 25 09:11:56 CET 2013
On 01/25/13 00:11, Alexander Klenin wrote:
> Do I understand correctly that you are speaking about this article:
> http://opensoft.homeip.net/articles/iterator_pattern.pdf ?
Yes.
> As far as I understand, since iterators described in the article do
> not have the concept of a current item,
The current item is returned when you call Next or Previous on the
iterator. You use HasNext and HasPrevious in the loop. As the article
describes, my Iterator implementation is based on the Java-style where
the pointer in the list sits between items - there is a graph of that in
the article too.
> they also do not have concept of an index, and hence are not relevant
> in the context of this discussion.
No need for an index value because Next and Previous returns what you
need. Also the one Iterator I implemented can take a regular expression
(regex), thus you can iterator a list but filtered results are returned.
The article shows this somewhere near the end. So the traditional
"index" value doesn't or can't apply, because it can skip many or all
items in the list.
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
More information about the fpc-devel
mailing list