Skip to content

Commit

Permalink
fix: filter takes snapshot iterator item
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 committed Jan 28, 2025
1 parent d439c1d commit 695f5d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions corelib/src/iter/adapters/filter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ pub impl FilterIterator<
I,
P,
impl TIter: Iterator<I>,
+core::ops::Fn<P, (TIter::Item,)>[Output: bool],
+core::ops::Fn<P, (@TIter::Item,)>[Output: bool],
+Destruct<I>,
+Destruct<P>,
+Copy<TIter::Item>,
+Copy<P>,
+Destruct<TIter::Item>,
> of Iterator<Filter<I, P>> {
Expand Down
9 changes: 4 additions & 5 deletions corelib/src/iter/traits/iterator.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::iter::adapters::{
Enumerate, Filter, Map, Zip, enumerated_iterator, filter_iterator, mapped_iterator,
Enumerate, Filter, Map, Peekable, Zip, enumerated_iterator, filter_iterator, mapped_iterator,
peekable_iterator, zipped_iterator,
};
use crate::iter::traits::{Product, Sum};
Expand Down Expand Up @@ -388,7 +388,7 @@ pub trait Iterator<T> {
}

/// Creates an iterator which uses a closure to determine if an element
/// should be yielded.
/// should be yielded. The closure takes each element as a snapshot.
///
/// Given an element the closure must return `true` or `false`. The returned
/// iterator will yield only the elements for which the closure returns
Expand All @@ -401,7 +401,7 @@ pub trait Iterator<T> {
/// ```
/// let a = array![0_u32, 1, 2];
///
/// let mut iter = a.into_iter().filter(|x| x > 0);
/// let mut iter = a.into_iter().filter(|x| *x > 0);
///
/// assert_eq!(iter.next(), Option::Some(1));
/// assert_eq!(iter.next(), Option::Some(2));
Expand All @@ -412,10 +412,9 @@ pub trait Iterator<T> {
#[inline]
fn filter<
P,
+core::ops::Fn<P, (Self::Item,)>[Output: bool],
+core::ops::Fn<P, (@Self::Item,)>[Output: bool],
+Destruct<P>,
+Destruct<T>,
+Copy<Self::Item>,
+Destruct<Self::Item>,
>(
self: T, predicate: P,
Expand Down
2 changes: 1 addition & 1 deletion corelib/src/test/iter_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn test_iter_find() {

#[test]
fn test_iter_adapter_filter() {
let mut iter = array![0_u32, 1, 2].into_iter().filter(|x| x > 0);
let mut iter = array![0_u32, 1, 2].into_iter().filter(|x| *x > 0);
assert_eq!(iter.next(), Option::Some(1));
assert_eq!(iter.next(), Option::Some(2));
assert_eq!(iter.next(), Option::None);
Expand Down

0 comments on commit 695f5d2

Please sign in to comment.