From: Richard W.M. Jones Date: Mon, 20 Feb 2012 15:45:34 +0000 (+0000) Subject: Add filter_map utility. X-Git-Tag: 0.0.1~30 X-Git-Url: http://git.annexia.org/?p=whenjobs.git;a=commitdiff_plain;h=973fae9b3be949857be0612dd71280156121f82e Add filter_map utility. --- 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. *)