ref: 7ef2abad32fe3b273f16eeb28d63a63229dca3a6
parent: 4e1e9e32cfb509accccb254cd3c71824a64abd85
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Dec 30 16:33:08 EST 2015
Add support for by-line iteration to bio.
--- /dev/null
+++ b/lib/bio/iter.myr
@@ -1,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#)
+ }
+;;