mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -05:00
add CCResult.fold_ok (closes #107)
This commit is contained in:
parent
ee69bdcab8
commit
02b2a21e33
2 changed files with 15 additions and 2 deletions
|
|
@ -114,6 +114,15 @@ let fold ~ok ~error x = match x with
|
|||
| Ok x -> ok x
|
||||
| Error s -> error s
|
||||
|
||||
let fold_ok f acc r = match r with
|
||||
| Ok x -> f acc x
|
||||
| Error _ -> acc
|
||||
|
||||
(*$=
|
||||
42 (fold_ok (+) 2 (Ok 40))
|
||||
40 (fold_ok (+) 40 (Error "foo"))
|
||||
*)
|
||||
|
||||
let is_ok = function
|
||||
| Ok _ -> true
|
||||
| Error _ -> false
|
||||
|
|
|
|||
|
|
@ -101,9 +101,13 @@ val fold : ok:('a -> 'b) -> error:('err -> 'b) -> ('a, 'err) t -> 'b
|
|||
(** [fold ~ok ~error e] opens [e] and, if [e = Ok x], returns
|
||||
[ok x], otherwise [e = Error s] and it returns [error s]. *)
|
||||
|
||||
val is_ok : ('a, 'err) t -> bool
|
||||
(** Return true if Ok/
|
||||
val fold_ok : ('a -> 'b -> 'a) -> 'a -> ('b, _) t -> 'a
|
||||
(** [fold_ok f acc r] will compute [f acc x] if [r=Ok x],
|
||||
and return [acc] otherwise, as if the result were a mere option.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val is_ok : ('a, 'err) t -> bool
|
||||
(** Return true if Ok
|
||||
@since 1.0 *)
|
||||
|
||||
val is_error : ('a, 'err) t -> bool
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue