Skip to content

Commit

Permalink
fix: extend iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 committed Jan 23, 2025
1 parent e72997d commit 0ee7864
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
12 changes: 2 additions & 10 deletions corelib/src/array.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -870,16 +870,8 @@ impl ArrayFromIterator<T, +Drop<T>> of crate::iter::FromIterator<Array<T>, T> {
}

impl ArrayExtend<T, +Drop<T>> of crate::iter::Extend<Array<T>, T> {
fn extend<
I,
impl IntoIter: IntoIterator<I>,
+TypeEqual<IntoIter::Iterator::Item, T>,
+Destruct<IntoIter::IntoIter>,
+Destruct<I>,
>(
ref self: Array<T>, iter: I,
) {
for elem in iter.into_iter() {
fn extend<I, +Iterator<I>[Item: T], +Destruct<I>>(ref self: Array<T>, iter: I) {
for elem in iter {
self.append(elem);
};
}
Expand Down
12 changes: 1 addition & 11 deletions corelib/src/iter/traits/collect.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::metaprogramming::TypeEqual;

/// Conversion from an [`Iterator`].
///
/// By implementing `FromIterator` for a type, you define how it will be
Expand Down Expand Up @@ -220,14 +218,6 @@ impl SnapshotFixedSizeArrayIntoIterator<
/// ```
pub trait Extend<T, A> {
/// Extends a collection with the contents of an iterator.
fn extend<
I,
impl IntoIter: IntoIterator<I>,
+TypeEqual<IntoIter::Iterator::Item, A>,
+Destruct<IntoIter::IntoIter>,
+Destruct<I>,
>(
ref self: T, iter: I,
);
fn extend<I, +Iterator<I>[Item: A], +Destruct<I>>(ref self: T, iter: I);
}

2 changes: 1 addition & 1 deletion corelib/src/test/array_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn test_array_from_iterator() {
#[test]
fn test_array_extend() {
let mut arr: Array<u32> = array![1, 2, 3];
arr.extend((4..6_u32));
arr.extend((4..6_u32).into_iter());
assert_eq!(arr, array![1, 2, 3, 4, 5]);
}

Expand Down

0 comments on commit 0ee7864

Please sign in to comment.