From ca6abc9a3c4e7b5ab614dfa097f87996a6383d68 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Tue, 11 Oct 2005 08:24:33 +0000 Subject: [PATCH] added list_concat --- helm/ocaml/extlib/hExtlib.ml | 9 +++++++++ helm/ocaml/extlib/hExtlib.mli | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/helm/ocaml/extlib/hExtlib.ml b/helm/ocaml/extlib/hExtlib.ml index 31cf86a75..ceb9c8d8b 100644 --- a/helm/ocaml/extlib/hExtlib.ml +++ b/helm/ocaml/extlib/hExtlib.ml @@ -104,6 +104,15 @@ let rec filter_map f = | None -> filter_map f tl | Some v -> v :: filter_map f tl) +let list_concat ?(sep = []) = + let rec aux acc = + function + | [] -> [] + | [ last ] -> List.flatten (List.rev (last :: acc)) + | hd :: tl -> aux ([sep; hd] @ acc) tl + in + aux [] + (** {2 File predicates} *) let is_dir fname = diff --git a/helm/ocaml/extlib/hExtlib.mli b/helm/ocaml/extlib/hExtlib.mli index 46ea0b9ce..e40920350 100644 --- a/helm/ocaml/extlib/hExtlib.mli +++ b/helm/ocaml/extlib/hExtlib.mli @@ -54,8 +54,9 @@ val trim_blanks: string -> string (** strip heading and trailing blanks *) (** {2 List processing} *) -val list_uniq: 'a list -> 'a list (* uniq unix filter on lists *) -val filter_map: ('a -> 'b option) -> 'a list -> 'b list (* filter + map *) +val list_uniq: 'a list -> 'a list (** uniq unix filter on lists *) +val filter_map: ('a -> 'b option) -> 'a list -> 'b list (** filter + map *) +val list_concat: ?sep:'a list -> 'a list list -> 'a list (**String.concat-like*) (** {2 Debugging & Profiling} *) -- 2.39.2