summaryrefslogtreecommitdiff
path: root/tnslc/utils/iterator.tnsl
blob: b38d71f7bdf050075b0d5bc8fe81a2c05fb0030c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
struct Iterator {
	~Vector v,
	int pos
}

/; method Iterator
	/; init(~Vector v)
		self.v = v
		self.pos = 0
	;/

	/; get [~void]
		return self.v`.get(self.pos)
	;/

	/; next
		/; if (self.pos + 1 < self.v`.count)
			self.pos++
		;/
	;/

	/; prev
		/; if (self.pos > 0)
			self.pos--
		;/
	;/
;/