summaryrefslogtreecommitdiff
path: root/lib/bio
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-02-01 00:18:18 -0800
committerOri Bernstein <ori@eigenstate.org>2017-02-01 00:18:18 -0800
commita57d9fd3e0a6dd268872ed89d6a41c723d909b2e (patch)
treeb23a253b2d2d1bde9a789fc775d73ee7a957b024 /lib/bio
parent2c8775977321483c7a16b55c7884612f9f770e6a (diff)
downloadmc-a57d9fd3e0a6dd268872ed89d6a41c723d909b2e.tar.gz
Implement 'bychar' for iterating characters.
Diffstat (limited to 'lib/bio')
-rw-r--r--lib/bio/iter.myr24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/bio/iter.myr b/lib/bio/iter.myr
index ba7d765..c54b342 100644
--- a/lib/bio/iter.myr
+++ b/lib/bio/iter.myr
@@ -3,9 +3,12 @@ use "bio"
pkg bio =
type lineiter = file#
+ type chariter = file#
impl iterable lineiter -> byte[:]
+ impl iterable chariter -> char
const byline : (f : file# -> lineiter)
+ const bychar : (f : file# -> chariter)
;;
const byline = {f
@@ -29,3 +32,24 @@ impl iterable lineiter -> byte[:] =
std.slfree(outp#)
}
;;
+
+const bychar = {f
+ -> (f : chariter)
+}
+
+impl iterable chariter -> char =
+ __iternext__ = {itp, outp : char#
+ match bio.getc((itp# : file#))
+ | `Ok c:
+ outp# = c
+ -> true
+ | `Eof:
+ -> false
+ | `Err _:
+ -> false
+ ;;
+ }
+
+ __iterfin__ = {itp, outp
+ }
+;;