mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 19:55:31 -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
|
| Ok x -> ok x
|
||||||
| Error s -> error s
|
| 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
|
let is_ok = function
|
||||||
| Ok _ -> true
|
| Ok _ -> true
|
||||||
| Error _ -> false
|
| 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
|
(** [fold ~ok ~error e] opens [e] and, if [e = Ok x], returns
|
||||||
[ok x], otherwise [e = Error s] and it returns [error s]. *)
|
[ok x], otherwise [e = Error s] and it returns [error s]. *)
|
||||||
|
|
||||||
val is_ok : ('a, 'err) t -> bool
|
val fold_ok : ('a -> 'b -> 'a) -> 'a -> ('b, _) t -> 'a
|
||||||
(** Return true if Ok/
|
(** [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 *)
|
@since 1.0 *)
|
||||||
|
|
||||||
val is_error : ('a, 'err) t -> bool
|
val is_error : ('a, 'err) t -> bool
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue