zipcartesian: rewording for cleanliness
This commit is contained in:
@@ -1,24 +1,34 @@
|
|||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
|
||||||
pub trait ZipCartesianExt: Iterator {
|
pub trait ZipCartesianExt: Iterator + Clone
|
||||||
|
where
|
||||||
|
Self::Item: Copy,
|
||||||
|
{
|
||||||
fn zip_cartesian<B>(
|
fn zip_cartesian<B>(
|
||||||
self,
|
self,
|
||||||
b: B,
|
b: B,
|
||||||
) -> impl Iterator<Item = (Self::Item, B::Item)> + Clone
|
) -> impl Iterator<Item = (Self::Item, B::Item)> + Clone
|
||||||
where
|
where
|
||||||
Self::Item: Copy,
|
B::Item: Copy,
|
||||||
Self: Sized + Clone,
|
B: Iterator + Clone;
|
||||||
B: Iterator<Item: Copy> + 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.
|
/// Exhaustive coupling of two iterators.
|
||||||
/// For each x in `self`: for each y in `b`: yield (x, y).
|
/// For each x in `self`: for each y in `b`: yield (x, y).
|
||||||
/// b: B must implement `Clone`.
|
/// b: B must implement `Clone`.
|
||||||
fn zip_cartesian<B: Iterator<Item: Copy> + Clone>(
|
fn zip_cartesian<B>(
|
||||||
self,
|
self,
|
||||||
b: B,
|
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| {
|
self.flat_map(move |a_item| {
|
||||||
b.clone().map(move |b_item| (a_item, b_item))
|
b.clone().map(move |b_item| (a_item, b_item))
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user