summaryrefslogtreecommitdiff
path: root/lib/bio
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-12-30 21:33:08 -0800
committerOri Bernstein <ori@eigenstate.org>2015-12-30 21:33:08 -0800
commit7ef2abad32fe3b273f16eeb28d63a63229dca3a6 (patch)
treea1235536dc5c0093967e181d951bf1af626346d2 /lib/bio
parent4e1e9e32cfb509accccb254cd3c71824a64abd85 (diff)
downloadmc-7ef2abad32fe3b273f16eeb28d63a63229dca3a6.tar.gz
Add support for by-line iteration to bio.
Diffstat (limited to 'lib/bio')
-rw-r--r--lib/bio/iter.myr31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/bio/iter.myr b/lib/bio/iter.myr
new file mode 100644
index 0000000..e0c103e
--- /dev/null
+++ b/lib/bio/iter.myr
@@ -0,0 +1,31 @@
+use std
+use "bio.use"
+
+pkg bio =
+ type lineiter = file#
+ impl iterable lineiter -> byte[:]
+
+ const lineiter : (f : file# -> lineiter)
+;;
+
+const lineiter = {f
+ -> f castto(lineiter)
+}
+
+impl iterable lineiter -> byte[:] =
+ __iternext__ = {itp, outp
+ match bio.readln(itp# castto(file#))
+ | `Ok ln:
+ outp# = ln
+ -> true
+ | `Eof:
+ -> false
+ | `Err _:
+ -> false
+ ;;
+ }
+
+ __iterfin__ = {itp, outp
+ std.slfree(outp#)
+ }
+;;