-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(corelib): Iterator::peekable #7097
base: main
Are you sure you want to change the base?
Conversation
Not complete: still some compilation issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is required to be added to the prelude in that case, but lets postpone that.
Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @hudem1)
a discussion (no related file):
@gilbens-starkware for 2nd eye.
corelib/src/test/iter_test.cairo
line 44 at r1 (raw file):
let xs = array![1, 2, 3]; let mut iter = xs.into_iter().peekable();
Suggestion:
fn test_iter_adapter_peekable() {
let mut iter = (1..4).into_iter().peekable();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @hudem1)
corelib/src/iter/traits/iterator.cairo
line 305 at r1 (raw file):
#[must_use] fn peekable(self: T) -> Peekable<T, Self::Item> { peekable_iterator(self)
We should find the impl we in, but meanwhile, maybe this will work:
Suggestion:
peekable_iterator::<T, Self>(self)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Reviewable status: 2 of 5 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware and @orizi)
corelib/src/iter/traits/iterator.cairo
line 305 at r1 (raw file):
Previously, gilbens-starkware (Gil Ben-Shachar) wrote…
We should find the impl we in, but meanwhile, maybe this will work:
Thank you for the suggestion. I tried but it doesn't work, it says Unknown impl
over the Self
, and running the test still gives the same error Error: Compilation failed without any diagnostics.
.
corelib/src/test/iter_test.cairo
line 44 at r1 (raw file):
let xs = array![1, 2, 3]; let mut iter = xs.into_iter().peekable();
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: 2 of 5 files reviewed, 3 unresolved discussions (waiting on @gilbens-starkware and @hudem1)
corelib/src/iter/adapters/peekable.cairo
line 17 at r2 (raw file):
pub fn peekable_iterator<I, impl IterI: Iterator<I>>(iter: I) -> Peekable<I, IterI::Item> { Peekable { iter, peeked: Option::None }
remove this - it would remove the requirement in the trait - that you don't actually need.
Suggestion:
pub fn peekable_iterator<I>(iter: I) -> Peekable<I, IterI::Item> {
Peekable { iter, peeked: Option::None }
corelib/src/iter/adapters/peekable.cairo
line 21 at r2 (raw file):
impl PeekableIterator< I, impl IterI: Iterator<I>, +Drop<I>, +Drop<IterI::Item>,
Suggestion:
I, impl IterI: Iterator<I>, +Destruct<I>, +Destruct<IterI::Item>,
I suggest the addition of
Iterator::peekable
to be able to usepeek()
on iterators.Example
I set my PR as a draft because i have 1 issue and 1 question, possibly related:
When I run my test, it says
Error: Compilation failed without any diagnostics.
. It does not display the reason of the compilation error and the test file doesn't show any particular error from the LS. I do get an LS error in theiterator.cairo
file sayingTrait has no implementation in context: core::iter::traits::iterator::Iterator::<T>.
, which does not make much sense to me as T obviously implements Iterator as we are in theIterator<T>
trait.I am unsure about how to use the custom trait for the
peek
method. I exported it in theadapters.cairo
anditer.cairo
files to be able to import it in my test file, but I am not sure it is the correct way to use it.