Skip to content

Commit 1f69c53

Browse files
yizhepkuPhilippe-Cholet
authored andcommitted
multi_cartesian_product: document the nullary product
Regression test for #337
1 parent 33541c4 commit 1f69c53

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,16 @@ pub trait Itertools: Iterator {
11811181
/// assert_eq!(multi_prod.next(), Some(vec![1, 3, 5]));
11821182
/// assert_eq!(multi_prod.next(), None);
11831183
/// ```
1184+
///
1185+
/// If the adapted iterator is empty, the result is an iterator yielding a single empty vector.
1186+
/// This is known as the [nullary cartesian product](https://en.wikipedia.org/wiki/Empty_product#Nullary_Cartesian_product).
1187+
///
1188+
/// ```
1189+
/// use itertools::Itertools;
1190+
/// let mut nullary_cartesian_product = (0..0).map(|i| (i * 2)..(i * 2 + 2)).multi_cartesian_product();
1191+
/// assert_eq!(nullary_cartesian_product.next(), Some(vec![]));
1192+
/// assert_eq!(nullary_cartesian_product.next(), None);
1193+
/// ```
11841194
#[cfg(feature = "use_alloc")]
11851195
fn multi_cartesian_product(self) -> MultiProduct<<Self::Item as IntoIterator>::IntoIter>
11861196
where

0 commit comments

Comments
 (0)