| 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
| 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 =