shithub: mc

ref: ff88594df5c5df6fb8f227ab8e5df3529ba6e72f
dir: /test/custiter.myr/

View raw version
use std

type range = struct
	lo	: int
	hi	: int
;;

/* iterate up to 100 */
impl iterable range -> int =
        __iternext__ = {rng, output
		if rng.lo > rng.hi
			-> false
		else
			output# = rng.lo++
                        -> true
                ;;
        }

        __iterfin__ = {it, val
        }
;;

const main = {
	var r : range
	var x : int

	r = [.lo=6, .hi=11]
	for v : r
		x = v
                std.put("{}", x)
        ;;
	std.put("\n")
}