shithub: mc

ref: 9c52b9aaf791386a95a6eb11e27d2a982b72d872
dir: /lib/bio/iter.myr/

View raw version
use std
use "bio"

pkg bio =
	type lineiter = file#
	impl iterable lineiter -> byte[:]

	const byline	: (f : file# -> lineiter)
;;

const byline = {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#)
	}
;;