diff --git a/enum.ml b/enum.ml index d1274a16..31067fa0 100644 --- a/enum.ml +++ b/enum.ml @@ -399,9 +399,10 @@ let intersperse x enum = (** Cartesian product *) let product a b = fun () -> - (* [a] is the outer relation *) - let gen_a = a () in - try + if is_empty a || is_empty b then fun () -> raise EOG + else + (* [a] is the outer relation *) + let gen_a = a () in (* current element of [a] *) let cur_a = ref (gen_a ()) in let gen_b = ref (b ()) in @@ -414,8 +415,6 @@ let product a b = next () in next - with EOG -> - raise EOG (* [a] is empty *) let permutations enum = failwith "not implemented" (* TODO *) diff --git a/enum.mli b/enum.mli index 3e44dce5..4406b45f 100644 --- a/enum.mli +++ b/enum.mli @@ -109,8 +109,7 @@ val drop : int -> 'a t -> 'a t (** Drop n elements *) val filter : ('a -> bool) -> 'a t -> 'a t - (** Filter out elements that do not satisfy the predicate. The outer - enum must be finite. *) + (** Filter out elements that do not satisfy the predicate. *) val takeWhile : ('a -> bool) -> 'a t -> 'a t (** Take elements while they satisfy the predicate *) @@ -133,7 +132,8 @@ val zipIndex : 'a t -> (int * 'a) t (** {2 Complex combinators} *) val round_robin : 'a t t -> 'a t - (** Pick elements fairly in each sub-enum *) + (** Pick elements fairly in each sub-enum. The given enum + must be finite (not its elements, though). *) val persistent : 'a generator -> 'a t (** Store content of the generator in memory, to be able to iterate on it