aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util.ml10
-rw-r--r--lib/util.mli5
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml
index d1e24e3216..9428aa134d 100644
--- a/lib/util.ml
+++ b/lib/util.ml
@@ -871,6 +871,16 @@ let list_cartesians op init ll =
let list_combinations l = list_cartesians (fun x l -> x::l) [] l
+(* Keep only those products that do not return None *)
+
+let rec list_cartesian_filter op l1 l2 =
+ list_map_append (fun x -> list_map_filter (op x) l2) l1
+
+(* Keep only those products that do not return None *)
+
+let rec list_cartesians_filter op init ll =
+ List.fold_right (list_cartesian_filter op) ll [init]
+
(* Drop the last element of a list *)
let rec list_drop_last = function [] -> assert false | hd :: [] -> [] | hd :: tl -> hd :: list_drop_last tl
diff --git a/lib/util.mli b/lib/util.mli
index 46fd7b02ed..8b27e61583 100644
--- a/lib/util.mli
+++ b/lib/util.mli
@@ -178,6 +178,11 @@ val list_cartesian : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
val list_cartesians : ('a -> 'b -> 'b) -> 'b -> 'a list list -> 'b list
(* list_combinations [[a;b];[c;d]] returns [[a;c];[a;d];[b;c];[b;d]] *)
val list_combinations : 'a list list -> 'a list list
+(* Keep only those products that do not return None *)
+val list_cartesian_filter :
+ ('a -> 'b -> 'c option) -> 'a list -> 'b list -> 'c list
+val list_cartesians_filter :
+ ('a -> 'b -> 'b option) -> 'b -> 'a list list -> 'b list
val list_union_map : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b