]> matita.cs.unibo.it Git - helm.git/blobdiff - components/extlib/hExtlib.ml
added split_nth
[helm.git] / components / extlib / hExtlib.ml
index 32f33bd2be735bbb3d5df18d4d63cc0c62e863e9..3cc6c9bb5c0bc876f74d35de8868f3231a56c14e 100644 (file)
@@ -172,6 +172,14 @@ let rec list_findopt f l =
   in
   aux l
 
+let split_nth n l =
+  let rec aux acc n l =
+    match n, l with
+    | 0, _ -> List.rev acc, l
+    | n, [] -> raise (Failure "HExtlib.split_nth")
+    | n, hd :: tl -> aux (hd :: acc) (n - 1) tl in
+  aux [] n l
+
 (** {2 File predicates} *)
 
 let is_dir fname =