summaryrefslogtreecommitdiff
path: root/tnslc/utils/iterator.tnsl
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/utils/iterator.tnsl')
-rw-r--r--tnslc/utils/iterator.tnsl28
1 files changed, 28 insertions, 0 deletions
diff --git a/tnslc/utils/iterator.tnsl b/tnslc/utils/iterator.tnsl
new file mode 100644
index 0000000..b38d71f
--- /dev/null
+++ b/tnslc/utils/iterator.tnsl
@@ -0,0 +1,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--
+ ;/
+ ;/
+;/
+