summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-06-16 13:56:55 -0700
committerOri Bernstein <ori@eigenstate.org>2015-06-16 13:56:55 -0700
commitf6f5d7086bc67d1c68d83d6f9bad1ea037e5e6c0 (patch)
treec3c6ca244243e53b3ccef454267573dbcbebb8d1 /libstd
parentac7fed3ddfa3caf2e2c97f221e023b75ec9693ac (diff)
downloadmc-f6f5d7086bc67d1c68d83d6f9bad1ea037e5e6c0.tar.gz
Rename/rearrange std.try, add defaulting variants.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/try.myr20
1 files changed, 18 insertions, 2 deletions
diff --git a/libstd/try.myr b/libstd/try.myr
index ea20f4e..da960ac 100644
--- a/libstd/try.myr
+++ b/libstd/try.myr
@@ -4,7 +4,9 @@ use "fmt.use"
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 try = {v
;;
}
-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
+ ;;
+}