From 1f69c5347ec6e353f0ca63f125a144b797450e58 Mon Sep 17 00:00:00 2001 From: YizhePKU Date: Wed, 3 Jan 2024 05:02:35 +0000 Subject: [PATCH] `multi_cartesian_product`: document the nullary product Regression test for #337 --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 126eb2221..1f39379e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1181,6 +1181,16 @@ pub trait Itertools: Iterator { /// assert_eq!(multi_prod.next(), Some(vec![1, 3, 5])); /// assert_eq!(multi_prod.next(), None); /// ``` + /// + /// If the adapted iterator is empty, the result is an iterator yielding a single empty vector. + /// This is known as the [nullary cartesian product](https://en.wikipedia.org/wiki/Empty_product#Nullary_Cartesian_product). + /// + /// ``` + /// use itertools::Itertools; + /// let mut nullary_cartesian_product = (0..0).map(|i| (i * 2)..(i * 2 + 2)).multi_cartesian_product(); + /// assert_eq!(nullary_cartesian_product.next(), Some(vec![])); + /// assert_eq!(nullary_cartesian_product.next(), None); + /// ``` #[cfg(feature = "use_alloc")] fn multi_cartesian_product(self) -> MultiProduct<::IntoIter> where