From 571d199acd4e6743a48f8f64f28c62d18182d04d Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 25 Jun 2009 15:10:43 +0000 Subject: [PATCH] new function --- helm/software/components/extlib/hExtlib.ml | 12 ++++++++++++ helm/software/components/extlib/hExtlib.mli | 2 ++ 2 files changed, 14 insertions(+) diff --git a/helm/software/components/extlib/hExtlib.ml b/helm/software/components/extlib/hExtlib.ml index 49d28bbb9..cccb46767 100644 --- a/helm/software/components/extlib/hExtlib.ml +++ b/helm/software/components/extlib/hExtlib.ml @@ -237,6 +237,18 @@ let filter_map_acc f acc l = acc, List.rev res ;; +let filter_map_monad f acc l = + let acc, res = + List.fold_left + (fun (acc, res) t -> + match f acc t with + | acc, None -> acc, res + | acc, Some 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 63bfc25f1..9c0980f76 100644 --- a/helm/software/components/extlib/hExtlib.mli +++ b/helm/software/components/extlib/hExtlib.mli @@ -86,6 +86,8 @@ val list_uniq: 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 filter_map_monad: ('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 -- 2.39.2