Skip to content
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): Option iterator #6942

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cairolover
Copy link
Contributor

Adds IntoIter and Iterator implementations for Option<T>

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator

@orizi orizi left a 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: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @cairolover)


corelib/src/test/option_test.cairo line 146 at r1 (raw file):

    let x: Option<u32> = Option::Some(5);
    let mut x_iter = x.into_iter();
    assert!(x_iter.next() == Option::Some(5));

Suggestion:

    assert!(x_iter.next() == Option::Some(5));
    assert!(x_iter.next() == Option::None);

corelib/src/option.cairo line 479 at r1 (raw file):

    fn next(ref self: OptionIter<T>) -> Option<T> {
        self.inner
    }

Suggestion:

impl OptionIterator<T> of Iterator<OptionIter<T>> {
    type Item = T;
    fn next(ref self: OptionIter<T>) -> Option<T> {
        let item = self.inner;
        self.inner = Option::None;
        item
    }

corelib/src/option.cairo line 489 at r1 (raw file):

        OptionIter { inner: self }
    }
}

Suggestion:

impl OptionIntoIterator<T> of IntoIterator<Option<T>> {
    type IntoIter = OptionIter<T>;

    #[inline]
    fn into_iter(self: Option<T>) -> OptionIter<T> {
        OptionIter { inner: self }
    }
}

Copy link
Contributor Author

@cairolover cairolover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @orizi)


corelib/src/test/option_test.cairo line 146 at r1 (raw file):

    let x: Option<u32> = Option::Some(5);
    let mut x_iter = x.into_iter();
    assert!(x_iter.next() == Option::Some(5));

Done.


corelib/src/option.cairo line 479 at r1 (raw file):

    fn next(ref self: OptionIter<T>) -> Option<T> {
        self.inner
    }

Done.


corelib/src/option.cairo line 489 at r1 (raw file):

        OptionIter { inner: self }
    }
}

Done.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @cairolover)


corelib/src/option.cairo line 147 at r2 (raw file):

//! [`into_iter`]: IntoIterator::into_iter

use crate::iter::{IntoIterator, Iterator};

probably remove the import itself - for the time being - in general until we break version 2023_01 where visibility modifiers will be ignored, we attempt to reduce the number of uses - as they add an actual viewable item in that case. (and here you use these still only once)

Code quote:

use crate::iter::{IntoIterator, Iterator};

Copy link
Contributor Author

@cairolover cairolover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @orizi)


corelib/src/option.cairo line 147 at r2 (raw file):

Previously, orizi wrote…

probably remove the import itself - for the time being - in general until we break version 2023_01 where visibility modifiers will be ignored, we attempt to reduce the number of uses - as they add an actual viewable item in that case. (and here you use these still only once)

Done.

Copy link
Contributor Author

@cairolover cairolover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @orizi)


corelib/src/option.cairo line 147 at r2 (raw file):

Previously, cairolover (cairolover) wrote…

Done.

by the way - shouldn't iterator traits be part of the prelude?

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @cairolover)


corelib/src/option.cairo line 147 at r2 (raw file):

Previously, cairolover (cairolover) wrote…

by the way - shouldn't iterator traits be part of the prelude?

quite possibly it would make more sense.


a discussion (no related file):
@enitrat for 2nd eye doc.

Copy link
Contributor

@enitrat enitrat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @cairolover)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r4, all commit messages.
Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @cairolover)


corelib/src/test/option_test.cairo line 1 at r4 (raw file):

use crate::iter::{IntoIterator, Iterator};

i believe shouldn't be required after rebase.

Code quote:

use crate::iter::{IntoIterator, Iterator};

Copy link
Contributor Author

@cairolover cairolover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @orizi)


corelib/src/test/option_test.cairo line 1 at r4 (raw file):

Previously, orizi wrote…

i believe shouldn't be required after rebase.

The other one has not been merged yet. I'll revisit once it is

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on @cairolover)


a discussion (no related file):
@gilbens-starkware for 2nd eye.

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on @orizi)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants