mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
join / both applicative functions for CCError
This commit is contained in:
parent
4d9b1d68ed
commit
eedce68653
2 changed files with 23 additions and 1 deletions
|
|
@ -162,6 +162,17 @@ let (<*>) f x = match f with
|
|||
| `Error s -> fail s
|
||||
| `Ok f -> map f x
|
||||
|
||||
let join t = match t with
|
||||
| `Ok (`Ok o) -> `Ok o
|
||||
| `Ok (`Error e) -> `Error e
|
||||
| (`Error _) as e -> e
|
||||
|
||||
let both x y =
|
||||
match x,y with
|
||||
| `Ok o, `Ok o' -> `Ok (o, o')
|
||||
| `Ok _, `Error e -> `Error e
|
||||
| `Error e, _ -> `Error e
|
||||
|
||||
(** {2 Collections} *)
|
||||
|
||||
let map_l f l =
|
||||
|
|
|
|||
|
|
@ -141,7 +141,18 @@ val pure : 'a -> ('a, 'err) t
|
|||
val (<*>) : ('a -> 'b, 'err) t -> ('a, 'err) t -> ('b, 'err) t
|
||||
(** [a <*> b] evaluates [a] and [b], and, in case of success, returns
|
||||
[`Ok (a b)]. Otherwise, it fails, and the error of [a] is chosen
|
||||
over the error of [b] if both fail *)
|
||||
over the error of [b] if both fail. *)
|
||||
|
||||
val join : (('a, 'err) t, 'err) t -> ('a, 'err) t
|
||||
(** [join t], in case of success, returns [`Ok o] from [`Ok (`Ok o)]. Otherwise,
|
||||
it fails with [`Error e] where [e] is the unwrapped error of [t].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val both : ('a, 'err) t -> ('b, 'err) t -> (('a * 'b), 'err) t
|
||||
(** [both a b], in case of success, returns [`Ok (o, o')] with the ok values
|
||||
of [a] and [b]. Otherwise, it fails, and the error of [a] is chosen over the
|
||||
error of [b] if both fail.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
(** {2 Infix}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue