shithub: mc

Download patch

ref: f6f5d7086bc67d1c68d83d6f9bad1ea037e5e6c0
parent: ac7fed3ddfa3caf2e2c97f221e023b75ec9693ac
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jun 16 09:56:55 EDT 2015

Rename/rearrange std.try, add defaulting variants.

--- a/libstd/try.myr
+++ b/libstd/try.myr
@@ -4,7 +4,9 @@
 
 pkg std =
 	generic try : (v : result(@a, @b) -> @a)
-	generic val : (v : option(@a) -> @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
@@ -14,9 +16,23 @@
 	;;
 }
 
-generic val = {v
+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
 	;;
 }