zipcartesian: rewording for cleanliness

This commit is contained in:
2026-04-14 19:07:22 +01:00
committed by oreodave
parent 8f4f72d0fd
commit 5d3e83d79c

View File

@@ -1,24 +1,34 @@
use std::iter::Iterator;
pub trait ZipCartesianExt: Iterator {
pub trait ZipCartesianExt: Iterator + Clone
where
Self::Item: Copy,
{
fn zip_cartesian<B>(
self,
b: B,
) -> impl Iterator<Item = (Self::Item, B::Item)> + Clone
where
Self::Item: Copy,
Self: Sized + Clone,
B: Iterator<Item: Copy> + Clone;
B::Item: Copy,
B: Iterator + Clone;
}
impl<I: Iterator<Item: Copy> + Clone> ZipCartesianExt for I {
impl<I> ZipCartesianExt for I
where
I: Iterator + Clone,
I::Item: Copy,
{
/// Exhaustive coupling of two iterators.
/// For each x in `self`: for each y in `b`: yield (x, y).
/// b: B must implement `Clone`.
fn zip_cartesian<B: Iterator<Item: Copy> + Clone>(
fn zip_cartesian<B>(
self,
b: B,
) -> impl Iterator<Item = (Self::Item, B::Item)> + Clone {
) -> impl Iterator<Item = (Self::Item, B::Item)> + Clone
where
B::Item: Copy,
B: Iterator + Clone,
{
self.flat_map(move |a_item| {
b.clone().map(move |b_item| (a_item, b_item))
})