]> matita.cs.unibo.it Git - helm.git/blobdiff - components/extlib/hExtlib.ml
added some hacks for the debian package
[helm.git] / components / extlib / hExtlib.ml
index 3cc6c9bb5c0bc876f74d35de8868f3231a56c14e..073c5695959480e657070af45a68ec3029132ef6 100644 (file)
@@ -153,6 +153,28 @@ 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_rev_map_filter_fold f v l =
+   let rec aux v a = function
+      | []       -> v, a
+      | hd :: tl -> 
+         begin match f v hd with
+           | v, None   -> aux v a tl
+           | v, Some b -> aux v (b :: a) tl 
+         end
+   in 
+   aux v [] l
+
 let list_concat ?(sep = []) =
   let rec aux acc =
     function
@@ -180,6 +202,11 @@ let split_nth n l =
     | 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 =