Eachin support for types other than TList

BlitzMax Forums/BlitzMax Programming/Eachin support for types other than TList

Pineapple(Posted 2012) [#1]
surely it's possible. how do?


GfK(Posted 2012) [#2]
surely it's possible. how do?
How do! Arr's life on t'other side o yon? Eee by gum, weer's me wippets?


skidracer(Posted 2012) [#3]
Help->Language->Collections


Pineapple(Posted 2012) [#4]
that's what I did, but it manages to not work. what am I getting wrong?

SuperStrict

Type queue
	Field front:queuenode
	Method enqueue:queuenode(data:Object)
		Local n:queuenode=queuenode.Create(data)
		If front lastnode().nxt=n Else front=n
		Return n
	End Method
	Method lastnode:queuenode()
		Local on:queuenode=front
		While on
			If on.nxt on=on.nxt Else Return on
		Wend
		Return Null
	End Method
	Method last:Object()
		Return lastnode().data
	End Method
	Method dequeuenode:queuenode()
		Local r:queuenode=front
		front=front.nxt
		Return r
	End Method
	Method dequeue:Object()
		Return dequeuenode().data
	End Method
	Method peeknode:queuenode()
		Return front
	End Method
	Method peek:Object()
		Return peeknode().data
	End Method
	Method count%()
		Local i%=0,on:queuenode=front
		While on
			i:+1;on=on.nxt
		Wend
		Return i
	End Method
	Method isempty%()
		If front Return 0
		Return 1
	End Method
	Function Create:queue()
		Return New queue
	End Function
	Method ObjectEnumerater:queueenum()
		Local q:queueenum=New queueenum
		q.node=front
		Return q
	End Method
End Type
Type queuenode
	Field data:Object
	Field nxt:queuenode
	Function Create:queuenode(data:Object)
		Local n:queuenode=New queuenode
		n.data=data
		Return n
	End Function
End Type

Type queueenum
	Field node:queuenode
	Method HasNext%()
		Return node.nxt<>Null
	End Method
	Method NextObject:Object()
		Local value:Object=node.data
		node=node.nxt
		Return value
	End Method
End Type


Local q:queue=New queue
q.enqueue("one")
q.enqueue("two")
q.enqueue("three")
q.enqueue("four")
q.enqueue("five")
For Local s$=EachIn q
	Print s
Next



Pineapple(Posted 2012) [#5]
oh. I misspelled 'enumerator'. I feel smart.