summaryrefslogtreecommitdiff
path: root/test/custiter.myr
diff options
context:
space:
mode:
Diffstat (limited to 'test/custiter.myr')
-rw-r--r--test/custiter.myr33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/custiter.myr b/test/custiter.myr
new file mode 100644
index 0000000..53238cd
--- /dev/null
+++ b/test/custiter.myr
@@ -0,0 +1,33 @@
+use std
+
+type range = struct
+ lo : int
+ hi : int
+;;
+
+/* iterate up to 100 */
+impl iterable range -> int =
+ __iternext__ = {rng, output
+ if rng.lo > rng.hi
+ -> false
+ else
+ output# = rng.lo++
+ -> true
+ ;;
+ }
+
+ __iterfin__ = {it, val
+ }
+;;
+
+const main = {
+ var r : range
+ var x : int
+
+ r = [.lo=6, .hi=11]
+ for v in r
+ x = v
+ std.put("{}", x)
+ ;;
+ std.put("\n")
+}