mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
Merge pull request #93 from orbitz/add-predicates-for-result
Add `is_ok` and `is_error`, simple predicates for testing a result
This commit is contained in:
commit
1e8f378f02
3 changed files with 19 additions and 0 deletions
|
|
@ -16,3 +16,4 @@
|
|||
- Johannes Kloos
|
||||
- Geoff Gole (@gsg)
|
||||
- Roma Sokolov (@little-arhat)
|
||||
- Malcolm Matalka (`orbitz`)
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue