Skip to content

Commit

Permalink
add function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Provenzano committed Nov 14, 2024
1 parent 9cfedad commit 4c9ab1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/CCResult.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ let is_error = function
| Ok _ -> false
| 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} *)

let guard f = try Ok (f ()) with e -> Error e
Expand Down
4 changes: 4 additions & 0 deletions src/core/CCResult.mli
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ val is_error : ('a, 'err) t -> bool
(** Return true if [Error].
@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} *)

val guard : (unit -> 'a) -> ('a, exn) t
Expand Down

0 comments on commit 4c9ab1c

Please sign in to comment.