Add is_ok and is_error, simple predicates for testing a result. This is useful for tests or asserts

This commit is contained in:
orbitz 2017-01-17 07:45:47 +01:00
parent 3f80e794ba
commit 13888edb4d
3 changed files with 19 additions and 0 deletions

View file

@ -16,3 +16,4 @@
- Johannes Kloos
- Geoff Gole (@gsg)
- Roma Sokolov (@little-arhat)
- Malcolm Matalka (`orbitz`)

View file

@ -98,6 +98,14 @@ let fold ~ok ~error x = match x with
| Ok x -> ok x
| Error s -> error s
let is_ok = function
| Ok _ -> true
| Error _ -> false
let is_error = function
| Ok _ -> false
| Error _ -> true
(** {2 Wrappers} *)
let guard f =

View file

@ -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
[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} *)
val guard : (unit -> 'a) -> ('a, exn) t