@@ -144,6 +144,8 @@ pub mod structs {
144
144
pub use crate :: with_position:: WithPosition ;
145
145
pub use crate :: zip_eq_impl:: ZipEq ;
146
146
pub use crate :: zip_longest:: ZipLongest ;
147
+ pub use crate :: zip_squash:: ZipSquash ;
148
+ pub use crate :: zip_stretch:: ZipStretch ;
147
149
pub use crate :: ziptuple:: Zip ;
148
150
}
149
151
@@ -235,6 +237,8 @@ mod unziptuple;
235
237
mod with_position;
236
238
mod zip_eq_impl;
237
239
mod zip_longest;
240
+ mod zip_squash;
241
+ mod zip_stretch;
238
242
mod ziptuple;
239
243
240
244
#[ macro_export]
@@ -4537,10 +4541,59 @@ pub trait Itertools: Iterator {
4537
4541
_ => Err ( sh) ,
4538
4542
}
4539
4543
}
4544
+
4545
+ /// Create an iterator which iterates over both this and the specified
4546
+ /// iterator simultaneously, yielding pairs of elements.
4547
+ ///
4548
+ /// Similar to [`Iterator::zip`] except elements are evenly sampled from
4549
+ /// the longest iterator.
4550
+ ///
4551
+ /// ```
4552
+ /// use itertools::Itertools;
4553
+ /// let a = vec![1, 2];
4554
+ /// let b = vec![1, 2, 3];
4555
+ ///
4556
+ /// let it = a.into_iter().zip_squash(b.into_iter());
4557
+ /// itertools::assert_equal(it, vec![(1, 1),(2,3)]);
4558
+ /// ```
4559
+ #[ inline]
4560
+ fn zip_squash < J > ( self , other : J ) -> ZipSquash < Self , J :: IntoIter >
4561
+ where
4562
+ J : IntoIterator ,
4563
+ <J as IntoIterator >:: IntoIter : ExactSizeIterator ,
4564
+ Self : ExactSizeIterator + Sized ,
4565
+ {
4566
+ zip_squash:: zip_squash ( self , other)
4567
+ }
4568
+ /// Create an iterator which iterates over both this and the specified
4569
+ /// iterator simultaneously, yielding pairs of elements.
4570
+ ///
4571
+ /// Always yielding the first and last elements of both iterators by using [`EitherOrBoth`].
4572
+ ///
4573
+ /// Similar to [`Itertools::zip_longest`] except elements in the shortest iterator are evenly
4574
+ /// spread.
4575
+ ///
4576
+ /// ```
4577
+ /// use itertools::Itertools;
4578
+ /// use itertools::EitherOrBoth;
4579
+ /// let a = vec![1, 2];
4580
+ /// let b = vec![1, 2, 3];
4581
+ ///
4582
+ /// let it = a.into_iter().zip_stretch(b.into_iter());
4583
+ /// itertools::assert_equal(it, vec![EitherOrBoth::Both(1, 1),EitherOrBoth::Right(2), EitherOrBoth::Both(2,3)]);
4584
+ /// ```
4585
+ #[ inline]
4586
+ fn zip_stretch < J > ( self , other : J ) -> ZipStretch < Self , J :: IntoIter >
4587
+ where
4588
+ J : IntoIterator ,
4589
+ <J as IntoIterator >:: IntoIter : ExactSizeIterator ,
4590
+ Self : ExactSizeIterator + Sized ,
4591
+ {
4592
+ zip_stretch:: zip_stretch ( self , other)
4593
+ }
4540
4594
}
4541
4595
4542
4596
impl < T > Itertools for T where T : Iterator + ?Sized { }
4543
-
4544
4597
/// Return `true` if both iterables produce equal sequences
4545
4598
/// (elements pairwise equal and sequences of the same length),
4546
4599
/// `false` otherwise.
0 commit comments