From 973fae9b3be949857be0612dd71280156121f82e Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 20 Feb 2012 15:45:34 +0000 Subject: [PATCH] Add filter_map utility. --- lib/whenutils.ml | 7 +++++++ lib/whenutils.mli | 3 +++ 2 files changed, 10 insertions(+) diff --git a/lib/whenutils.ml b/lib/whenutils.ml index 1fbb1c6..8cab30e 100644 --- a/lib/whenutils.ml +++ b/lib/whenutils.ml @@ -30,6 +30,13 @@ end module StringSet = Set.Make (String) +let rec filter_map f = function + | [] -> [] + | x :: xs -> + match f x with + | Some y -> y :: filter_map f xs + | None -> filter_map f xs + type whenexpr = | Expr_bool of bool | Expr_str of string diff --git a/lib/whenutils.mli b/lib/whenutils.mli index b2a8878..c935906 100644 --- a/lib/whenutils.mli +++ b/lib/whenutils.mli @@ -81,6 +81,9 @@ module StringSet : sig end (** A set of strings. *) +val filter_map : ('a -> 'b option) -> 'a list -> 'b list +(** Filter + map. *) + type whenexpr = | Expr_bool of bool (** A boolean constant. *) | Expr_str of string (** A string constant. *) -- 1.8.3.1