Stdlib: add Option.try_with

This commit is contained in:
Vincent Bernardoff 2017-12-15 17:00:50 +01:00
parent 9d30a8f4bf
commit f10d979432
2 changed files with 4 additions and 0 deletions

View File

@ -32,3 +32,5 @@ let first_some a b = match a, b with
| None, Some v -> Some v
| Some v, _ -> Some v
let try_with f =
try Some (f ()) with _ -> None

View File

@ -25,3 +25,5 @@ val unopt_map: f:('a -> 'b) -> default:'b -> 'a option -> 'b
(** First input of form [Some x], or [None] if none **)
val first_some: 'a option -> 'a option -> 'a option
(** [Some (f ())] if [f] does not raise, [None] otherwise *)
val try_with : (unit -> 'a) -> 'a option