From: Stefano Zacchiroli Date: Tue, 18 Jul 2006 14:21:56 +0000 (+0000) Subject: added split_nth X-Git-Tag: 0.4.95@7852~1189 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=8e6849498744f64cc2a60b60ac45ccacb169a6bc;p=helm.git added split_nth --- diff --git a/components/extlib/hExtlib.ml b/components/extlib/hExtlib.ml index 32f33bd2b..3cc6c9bb5 100644 --- a/components/extlib/hExtlib.ml +++ b/components/extlib/hExtlib.ml @@ -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 = diff --git a/components/extlib/hExtlib.mli b/components/extlib/hExtlib.mli index a38b09334..8de41f683 100644 --- a/components/extlib/hExtlib.mli +++ b/components/extlib/hExtlib.mli @@ -40,7 +40,6 @@ val safe_rmdir: string -> unit (** removes a dir if it exists and is empty *) val is_dir_empty: string -> bool (** checks if the dir is empty *) val rmdir_descend: string -> unit (** rmdir -p *) - (** find all _files_ whose name matches test under a filesystem root. * Test is passed the filename path relative to the given filesystem root *) val find: ?test:(string -> bool) -> string -> string list @@ -80,6 +79,12 @@ val list_concat: ?sep:'a list -> 'a list list -> 'a list (**String.concat-like*) val list_findopt: ('a -> 'b option) -> 'a list -> 'b option val flatten_map: ('a -> 'b list) -> 'a list -> 'b list + (** split_nth n l + * @returns two list, the first contains at least n elements, the second the + * remaining one + * @raise Failure when List.length l < n *) +val split_nth: int -> 'a list -> 'a list * 'a list + (** {2 Debugging & Profiling} *) type profiler = { profile : 'a 'b. ('a -> 'b) -> 'a -> 'b }