mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
adding opt_map to simplify result function application over optionals
This commit is contained in:
parent
a13fc12ff4
commit
289fc8af7b
2 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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. *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue