diff --git a/stdlib/.depend b/stdlib/.depend index 2de48883c..c6328a81f 100644 --- a/stdlib/.depend +++ b/stdlib/.depend @@ -409,7 +409,8 @@ stdlib__listLabels.cmx : \ stdlib__list.cmx \ stdlib__listLabels.cmi stdlib__listLabels.cmi : \ - stdlib__seq.cmi + stdlib__seq.cmi \ + stdlib__either.cmi stdlib__map.cmo : \ stdlib__seq.cmi \ stdlib__map.cmi diff --git a/stdlib/listLabels.mli b/stdlib/listLabels.mli index c98eaeef3..f3a5098dd 100644 --- a/stdlib/listLabels.mli +++ b/stdlib/listLabels.mli @@ -318,6 +318,21 @@ val partition : f:('a -> bool) -> 'a list -> 'a list * 'a list The order of the elements in the input list is preserved. *) +val partition_map : f:('a -> ('b, 'c) Either.t) -> 'a list -> 'b list * 'c list +(** [partition_map f l] returns a pair of lists [(l1, l2)] such that, + for each element [x] of the input list [l]: + - if [f x] is [Left y1], then [y1] is in [l1], and + - if [f x] is [Right y2], then [y2] is in [l2]. + + The output elements are included in [l1] and [l2] in the same + relative order as the corresponding input elements in [l]. + + In particular, [partition_map (fun x -> if p x then Left x else Right x) l] + is equivalent to [partition p l]. + + @since 4.12.0 +*) + (** {1 Association lists} *)