X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=components%2Fextlib%2FhExtlib.ml;h=d4572789ad55f39795d000fd09192e839cfee02f;hb=67cf4ce16c346991c8eda71576414f5c6324ab82;hp=32f33bd2be735bbb3d5df18d4d63cc0c62e863e9;hpb=c841003adea545c1bf12619906f1c61711a75deb;p=helm.git diff --git a/components/extlib/hExtlib.ml b/components/extlib/hExtlib.ml index 32f33bd2b..d4572789a 100644 --- a/components/extlib/hExtlib.ml +++ b/components/extlib/hExtlib.ml @@ -153,6 +153,17 @@ let rec filter_map f = | None -> filter_map f tl | Some v -> v :: filter_map f tl) +let list_rev_map_filter f l = + let rec aux a = function + | [] -> a + | hd :: tl -> + begin match f hd with + | None -> aux a tl + | Some b -> aux (b :: a) tl + end + in + aux [] l + let list_concat ?(sep = []) = let rec aux acc = function @@ -172,6 +183,19 @@ 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 + +let list_last l = + let l = List.rev l in + try List.hd l with exn -> raise (Failure "HExtlib.list_last") +;; + (** {2 File predicates} *) let is_dir fname =