mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
adding opt_map to simplify result function application over optionals (#397)
adding `Result.opt_map` to simplify result function application over optionals
This commit is contained in:
parent
a13fc12ff4
commit
4e79b72306
2 changed files with 12 additions and 0 deletions
|
|
@ -68,6 +68,14 @@ let of_exn_trace e =
|
||||||
in
|
in
|
||||||
Error res
|
Error res
|
||||||
|
|
||||||
|
let opt_map f e = match e with
|
||||||
|
| None -> Ok None
|
||||||
|
| Some x ->
|
||||||
|
begin match f x with
|
||||||
|
| Ok x -> Ok (Some x)
|
||||||
|
| Error e -> Error e
|
||||||
|
end
|
||||||
|
|
||||||
let map f e = match e with
|
let map f e = match e with
|
||||||
| Ok x -> Ok (f x)
|
| Ok x -> Ok (f x)
|
||||||
| Error s -> Error s
|
| Error s -> Error s
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,10 @@ val add_ctxf : ('a, Format.formatter, unit, ('b, string) t -> ('b, string) t) fo
|
||||||
]}
|
]}
|
||||||
@since 1.2 *)
|
@since 1.2 *)
|
||||||
|
|
||||||
|
val opt_map : ('a -> ('b, 'c) t) -> 'a option -> ('b option, 'c) t
|
||||||
|
(** Map a fallible operation through an option.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val map : ('a -> 'b) -> ('a, 'err) t -> ('b, 'err) t
|
val map : ('a -> 'b) -> ('a, 'err) t -> ('b, 'err) t
|
||||||
(** Map on success. *)
|
(** Map on success. *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue