diff --git a/corelib/src/iter/traits/iterator.cairo b/corelib/src/iter/traits/iterator.cairo index bd02e5d1d2f..46cff60a1a4 100644 --- a/corelib/src/iter/traits/iterator.cairo +++ b/corelib/src/iter/traits/iterator.cairo @@ -121,14 +121,25 @@ pub trait Iterator { /// assert_eq!(iter.next(), Option::None); /// ``` /// + /// Since the argument to `zip()` uses [`IntoIterator`], we can pass + /// anything that can be converted into an [`Iterator`], not just an + /// [`Iterator`] itself. For example: + /// + /// ``` + /// let mut iter = array![1, 2, 3].into_iter().zip(array![4, 5, 6]); + /// + /// assert_eq!(iter.next(), Option::Some((1, 4))); + /// assert_eq!(iter.next(), Option::Some((2, 5))); + /// assert_eq!(iter.next(), Option::Some((3, 6))); + /// assert_eq!(iter.next(), Option::None); + /// `` + /// /// [`enumerate`]: Iterator::enumerate /// [`next`]: Iterator::next #[inline] - fn zip //, +IntoIterator - >( + fn zip, +Destruct>( self: T, other: U, - ) -> Zip { - zipped_iterator(self, other //.into_iter() - ) + ) -> Zip { + zipped_iterator(self, other.into_iter()) } } diff --git a/corelib/src/test/iter_test.cairo b/corelib/src/test/iter_test.cairo index 988080b1432..36e8cb556dd 100644 --- a/corelib/src/test/iter_test.cairo +++ b/corelib/src/test/iter_test.cairo @@ -10,7 +10,7 @@ fn test_iter_adapter_map() { #[test] fn test_iterator_zip() { - let mut iter = array![1, 2, 3].into_iter().zip(array![4, 5, 6].into_iter()); + let mut iter = array![1, 2, 3].into_iter().zip(array![4, 5, 6]); assert_eq!(iter.next(), Option::Some((1, 4))); assert_eq!(iter.next(), Option::Some((2, 5))); @@ -18,10 +18,7 @@ fn test_iterator_zip() { assert_eq!(iter.next(), Option::None); // Nested zips - let mut iter = array![1, 2, 3] - .into_iter() - .zip(array![4, 5, 6].into_iter()) - .zip(array![7, 8, 9].into_iter()); + let mut iter = array![1, 2, 3].into_iter().zip(array![4, 5, 6]).zip(array![7, 8, 9]); assert_eq!(iter.next(), Option::Some(((1, 4), 7))); assert_eq!(iter.next(), Option::Some(((2, 5), 8)));