diff --git a/src/core/CCResult.ml b/src/core/CCResult.ml index 69bbab60..2a99f726 100644 --- a/src/core/CCResult.ml +++ b/src/core/CCResult.ml @@ -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 diff --git a/src/core/CCResult.mli b/src/core/CCResult.mli index 5347b3fd..21e339e4 100644 --- a/src/core/CCResult.mli +++ b/src/core/CCResult.mli @@ -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