From: Enrico Tassi Date: Wed, 10 Jun 2009 11:39:26 +0000 (+0000) Subject: new function filter_map_acc X-Git-Tag: make_still_working~3888 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=c6b50e06bd73a29501cafe599551db206193220b;p=helm.git new function filter_map_acc --- diff --git a/helm/software/components/extlib/.depend.opt b/helm/software/components/extlib/.depend.opt index 6d96e61e2..3f72e1d24 100644 --- a/helm/software/components/extlib/.depend.opt +++ b/helm/software/components/extlib/.depend.opt @@ -1,3 +1,12 @@ +componentsConf.cmi: +hExtlib.cmi: +hMarshal.cmi: +patternMatcher.cmi: +hLog.cmi: +trie.cmi: +hTopoSort.cmi: +refCounter.cmi: +graphvizPp.cmi: componentsConf.cmo: componentsConf.cmi componentsConf.cmx: componentsConf.cmi hExtlib.cmo: hExtlib.cmi diff --git a/helm/software/components/extlib/hExtlib.ml b/helm/software/components/extlib/hExtlib.ml index b2092c5b3..8451eb6b8 100644 --- a/helm/software/components/extlib/hExtlib.ml +++ b/helm/software/components/extlib/hExtlib.ml @@ -217,6 +217,18 @@ let rec filter_map f = | None -> filter_map f tl | Some v -> v :: filter_map f tl) +let filter_map_acc f acc l = + let acc, res = + List.fold_left + (fun (acc, res) t -> + match f acc t with + | None -> acc, res + | Some (acc, x) -> acc, x::res) + (acc,[]) l + in + acc, List.rev res +;; + let list_rev_map_filter f l = let rec aux a = function | [] -> a diff --git a/helm/software/components/extlib/hExtlib.mli b/helm/software/components/extlib/hExtlib.mli index 20e6c0192..a0b85ca4f 100644 --- a/helm/software/components/extlib/hExtlib.mli +++ b/helm/software/components/extlib/hExtlib.mli @@ -84,6 +84,9 @@ val trim_blanks: string -> string (** strip heading and trailing blanks *) val list_uniq: ?eq:('a->'a->bool) -> 'a list -> 'a list (** uniq unix filter on lists *) val filter_map: ('a -> 'b option) -> 'a list -> 'b list (** filter + map *) +val filter_map_acc: ('acc -> 'a -> ('acc * 'b) option) -> 'acc -> 'a list -> + 'acc * 'b list (** fold/filter + map *) + val list_rev_map_filter: ('a -> 'b option) -> 'a list -> 'b list val list_rev_map_filter_fold: ('c -> 'a -> 'c * 'b option) -> 'c -> 'a list -> 'c * 'b list val list_concat: ?sep:'a list -> 'a list list -> 'a list (**String.concat-like*)