diff --git a/src/lib_stdlib/tzList.ml b/src/lib_stdlib/tzList.ml index c091bc769..98f14760e 100644 --- a/src/lib_stdlib/tzList.ml +++ b/src/lib_stdlib/tzList.ml @@ -69,13 +69,15 @@ let rec remove nb = function let rec repeat n x = if n <= 0 then [] else x :: repeat (pred n) x -let take_n_unsorted n l = +let split_n n l = let rec loop acc n = function - | [] -> l - | _ when n <= 0 -> List.rev acc + | [] -> l, [] + | rem when n <= 0 -> List.rev acc, rem | x :: xs -> loop (x :: acc) (pred n) xs in loop [] n l +let take_n_unsorted n l = fst (split_n n l) + module Bounded(E: Set.OrderedType) : sig type t diff --git a/src/lib_stdlib/tzList.mli b/src/lib_stdlib/tzList.mli index 31099e35d..cfa313c45 100644 --- a/src/lib_stdlib/tzList.mli +++ b/src/lib_stdlib/tzList.mli @@ -23,6 +23,8 @@ val product : 'a list -> 'b list -> ('a * 'b) list is provided, it returns the [n] greatest element of [l]. *) val take_n: ?compare:('a -> 'a -> int) -> int -> 'a list -> 'a list +val split_n: int -> 'a list -> 'a list * 'a list + (** Bounded sequence: keep only the [n] greatest elements. *) module Bounded(E: Set.OrderedType) : sig type t