shithub: mc

ref: 11f0b71e1df81a2764d6dc0de9903f9a6d6ef7a6
dir: /libstd/option.myr/

View raw version
use "types.use"
use "fmt.use"
use "varargs.use"

pkg std =
	type option(@a) = union
		`Some @a
		`None
	;;

	generic try	: (v : option(@a), msg : byte[:], args : ... -> @a)
	generic tryv	: (v : option(@a), msg : byte[:], args : valist -> @a)
;;

generic try = {v, msg, args
	-> tryv(v, msg, vastart(&args))
}

generic tryv = {v, msg, ap
	match v
	| `None:	fatalv(1, msg, ap)
	| `Some a:	-> a
	;;
}