feat(Error): add Error.result/try_

This commit is contained in:
Simon Cruanes 2022-09-19 21:49:05 -04:00
parent e73bf4d3e5
commit 88a10dcf3a
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 8 additions and 0 deletions

View file

@ -8,3 +8,7 @@ let () =
| _ -> None)
let errorf msg = Fmt.ksprintf msg ~f:(fun s -> raise (Error s))
type nonrec 'a result = ('a, string) result
let try_ f = try Ok (f ()) with Error s -> Error s

View file

@ -2,3 +2,7 @@ exception Error of string
val errorf : ('a, Format.formatter, unit, 'b) format4 -> 'a
(** @raise Error when called *)
type nonrec 'a result = ('a, string) result
val try_ : (unit -> 'a) -> 'a result