Add Arg_spec.of_result{,_map}

This commit is contained in:
Jeremie Dimino 2018-03-01 20:16:46 +00:00
parent 09ff33951b
commit 945583ff43
2 changed files with 12 additions and 0 deletions

View File

@ -71,3 +71,12 @@ let quote_args =
| arg :: args -> quote :: arg :: loop quote args
in
fun quote args -> As (loop quote args)
let of_result = function
| Ok x -> x
| Error e -> Dyn (fun _ -> raise e)
let of_result_map res ~f =
match res with
| Ok x -> f x
| Error e -> Dyn (fun _ -> raise e)

View File

@ -46,3 +46,6 @@ val expand : dir:Path.t -> 'a t list -> 'a -> string list * Path.Set.t
(** [quote_args quote args] is [As \[quote; arg1; quote; arg2; ...\]] *)
val quote_args : string -> string list -> _ t
val of_result : ('a t, exn) result -> 'a t
val of_result_map : ('a, exn) result -> f:('a -> 'b t) -> 'b t