add function

This commit is contained in:
Sebastian Provenzano 2024-11-14 17:41:35 -06:00
parent 9cfedad7ba
commit 4c9ab1c659
2 changed files with 9 additions and 0 deletions

View file

@ -167,6 +167,11 @@ let is_error = function
| Ok _ -> false | Ok _ -> false
| Error _ -> true | Error _ -> true
let split_ok_error results =
results
|> CCList.partition_filter_map (fun x ->
match x with Ok o -> `Left o | Error e -> `Right e)
(** {2 Wrappers} *) (** {2 Wrappers} *)
let guard f = try Ok (f ()) with e -> Error e let guard f = try Ok (f ()) with e -> Error e

View file

@ -145,6 +145,10 @@ val is_error : ('a, 'err) t -> bool
(** Return true if [Error]. (** Return true if [Error].
@since 1.0 *) @since 1.0 *)
val split_ok_error : ('ok, 'error) result list -> 'ok list * 'error list
(** Split a list of results into [Ok]s and [Error]s.
@since 3.14.1 *)
(** {2 Wrappers} *) (** {2 Wrappers} *)
val guard : (unit -> 'a) -> ('a, exn) t val guard : (unit -> 'a) -> ('a, exn) t