diff --git a/src/baselib/ocsigen_lib_base.ml b/src/baselib/ocsigen_lib_base.ml index a02796328..0969197cb 100644 --- a/src/baselib/ocsigen_lib_base.ml +++ b/src/baselib/ocsigen_lib_base.ml @@ -173,6 +173,13 @@ module List = struct | [] -> [] | x :: xs -> chop (n-1) xs + let rec split_at n xs = + if n <= 0 + then [], xs + else match xs with + | [] -> [], [] + | x::xs -> let l,r = split_at (n-1) xs in x::l, r + end (*****************************************************************************) diff --git a/src/baselib/ocsigen_lib_base.mli b/src/baselib/ocsigen_lib_base.mli index bca337a76..3891feb2c 100644 --- a/src/baselib/ocsigen_lib_base.mli +++ b/src/baselib/ocsigen_lib_base.mli @@ -91,6 +91,7 @@ module List : sig val is_prefix : 'a list -> 'a list -> bool val chop : int -> 'a list -> 'a list + val split_at : int -> 'a list -> 'a list * 'a list end