Iterators / generators

BlitzMax Forums/BlitzMax Programming/Iterators / generators

Warpy(Posted 2008) [#1]
Just noticed something while looking at the TMap source:

Type numbers
	Field n1,n2
	
	Method New()
		n1=0
		n2=1
	End Method
	
	Method HasNext()
		Return 1
	End Method
	
	Method NextObject:Object()
		n3=n2
		n2=n1+n2
		n1=n3
		Return String(n2)
	End Method

	Method ObjectEnumerator:numbers()
		Return Self
	End Method
End Type

ne:numbers=New numbers
For a$=EachIn ne
	Print a
	If Int(a)>100000 End
Next



plash(Posted 2008) [#2]
I knew you could do that sort of thing in brisk, but not in blitzmax.


TomToad(Posted 2008) [#3]
this is somewhat discussed in the docs, under Help/Language/Collections.
The docs were a little vague, you can look at the TList module for an implementation.