shithub: mc

Download patch

ref: a57d9fd3e0a6dd268872ed89d6a41c723d909b2e
parent: 2c8775977321483c7a16b55c7884612f9f770e6a
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jan 31 19:18:18 EST 2017

Implement 'bychar' for iterating characters.

--- a/lib/bio/iter.myr
+++ b/lib/bio/iter.myr
@@ -3,9 +3,12 @@
 
 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
@@ -27,5 +30,26 @@
 
 	__iterfin__ = {itp, outp
 		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
 	}
 ;;