mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
Add is_ok and is_error, simple predicates for testing a result. This is useful for tests or asserts
This commit is contained in:
parent
3f80e794ba
commit
13888edb4d
3 changed files with 19 additions and 0 deletions
|
|
@ -16,3 +16,4 @@
|
||||||
- Johannes Kloos
|
- Johannes Kloos
|
||||||
- Geoff Gole (@gsg)
|
- Geoff Gole (@gsg)
|
||||||
- Roma Sokolov (@little-arhat)
|
- Roma Sokolov (@little-arhat)
|
||||||
|
- Malcolm Matalka (`orbitz`)
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,14 @@ 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 is_ok = function
|
||||||
|
| Ok _ -> true
|
||||||
|
| Error _ -> false
|
||||||
|
|
||||||
|
let is_error = function
|
||||||
|
| Ok _ -> false
|
||||||
|
| Error _ -> true
|
||||||
|
|
||||||
(** {2 Wrappers} *)
|
(** {2 Wrappers} *)
|
||||||
|
|
||||||
let guard f =
|
let guard f =
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,16 @@ 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
|
||||||
|
(** Return true if Ok/
|
||||||
|
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val is_error : ('a, 'err) t -> bool
|
||||||
|
(** Return true if Error
|
||||||
|
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
(** {2 Wrappers} *)
|
(** {2 Wrappers} *)
|
||||||
|
|
||||||
val guard : (unit -> 'a) -> ('a, exn) t
|
val guard : (unit -> 'a) -> ('a, exn) t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue