diff --git a/src/core/CCResult.ml b/src/core/CCResult.ml index 31c9f3e5..1a49efdb 100644 --- a/src/core/CCResult.ml +++ b/src/core/CCResult.ml @@ -68,6 +68,12 @@ let of_exn_trace e = in Error res +let opt_map f e = match e with + | None -> Ok None + | Some x -> (match f x with + | Ok x -> Ok (Some x) + | Error e -> Error e) + let map f e = match e with | Ok x -> Ok (f x) | Error s -> Error s diff --git a/src/core/CCResult.mli b/src/core/CCResult.mli index 04213172..192a6f96 100644 --- a/src/core/CCResult.mli +++ b/src/core/CCResult.mli @@ -63,6 +63,9 @@ val add_ctxf : ('a, Format.formatter, unit, ('b, string) t -> ('b, string) t) fo ]} @since 1.2 *) +val opt_map : ('a -> ('b, 'c) t) -> 'a option -> ('b option, 'c) t +(** Map optional success *) + val map : ('a -> 'b) -> ('a, 'err) t -> ('b, 'err) t (** Map on success. *)