shithub: mc

ref: 04d647955b3d83e2fb3731d63887ae499809141e
dir: /libstd/try.myr/

View raw version
use "result.use"
use "option.use"
use "fmt.use"

pkg std =
	generic try : (v : result(@a, @b) -> @a)
	generic tryv : (v : result(@a, @b), d : @a -> @a)
	generic get : (v : option(@a) -> @a)
	generic getv : (v : option(@a), d : @a -> @a)
;;

generic try = {v
	match v
	| `Ok x:	-> x
	| `Fail m:	fatal("error: {}\n", m)
	;;
}

generic tryv = {v, d
	match v
	| `Ok x:	-> x
	| `Fail m:	-> d
	;;
}

generic get = {v
	match v
	| `Some x:	-> x
	| `None:	fatal("error: option had `None\n")
	;;
}

generic getv = {v, d
	match v
	| `Some x:	-> x
	| `None:	-> d
	;;
}