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): Result iterator #6933

Merged
merged 6 commits into from
Jan 6, 2025

Conversation

cairolover
Copy link
Contributor

Adds IntoIter and Iter implementations for Result<T, E>.
Follows a format similar to SpanIter and ArrayIter, with a new ResultIter struct.

@reviewable-StarkWare
Copy link

This change is Reviewable

@cairolover cairolover force-pushed the feat/result-iterators branch from 1e6d1e9 to 9b67600 Compare December 26, 2024 15:59
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


corelib/src/test/result_test.cairo line 2 at r2 (raw file):

use crate::result::{Result, ResultTraitImpl};
use crate::iter::{IntoIterator, Iterator};

should this not be included automatically in 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.

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


corelib/src/result.cairo line 577 at r2 (raw file):

impl ResultIntoIterator<T, E, +Copy<T>, +Destruct<T>, +Destruct<E>> of IntoIterator<Result<T, E>> {
    type IntoIter = ResultIter<T>;

consider just using OptionIter here after it is merged.

Suggestion:

impl ResultIntoIterator<T, E, +Copy<T>, +Destruct<T>, +Destruct<E>> of IntoIterator<Result<T, E>> {
    type IntoIter = OptionIter<T>;

corelib/src/test/result_test.cairo line 265 at r2 (raw file):

    let x: Result<u32, ByteArray> = Result::Ok(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);

@cairolover cairolover force-pushed the feat/result-iterators branch 2 times, most recently from e39c3a0 to 3f8b3ff Compare January 2, 2025 13:23
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 3 files reviewed, 3 unresolved discussions (waiting on @orizi)


corelib/src/result.cairo line 577 at r2 (raw file):

Previously, orizi wrote…

consider just using OptionIter here after it is merged.

Done.


corelib/src/test/result_test.cairo line 265 at r2 (raw file):

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

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 all commit messages.
Reviewable status: 0 of 3 files reviewed, 4 unresolved discussions (waiting on @cairolover)


corelib/src/result.cairo line 578 at r3 (raw file):

    #[inline]
    fn into_iter(self: Result<T, E>) -> crate::option::OptionIter<T> {
        crate::option::OptionIter { inner: self.ok() }

and remove the pub(crate).

Suggestion:

        self.ok().into_iter()

@cairolover cairolover force-pushed the feat/result-iterators branch from 3f8b3ff to 40e182a Compare January 2, 2025 17:39
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 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @cairolover)


corelib/src/result.cairo line 557 at r4 (raw file):

impl ResultIntoIterator<
    T, E, +Copy<T>, +Destruct<T>, +Destruct<E>,

I don't think this should be required.

Suggestion:

    T, E, +Destruct<T>, +Destruct<E>,

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 3 files reviewed, 2 unresolved discussions (waiting on @orizi)


corelib/src/result.cairo line 578 at r3 (raw file):

Previously, orizi wrote…

and remove the pub(crate).

Done.


corelib/src/result.cairo line 557 at r4 (raw file):

Previously, orizi wrote…

I don't think this should be required.

Done.

@cairolover cairolover force-pushed the feat/result-iterators branch from 29647f0 to 9ddac7a Compare January 2, 2025 19:26
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:

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


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

@cairolover cairolover force-pushed the feat/result-iterators branch from 9ddac7a to fafa451 Compare January 4, 2025 21:17
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 r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (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.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @cairolover)


a discussion (no related file):

Previously, orizi wrote…

@gilbens-starkware for 2nd eye.

ping

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:

Reviewed 1 of 3 files at r4, 2 of 2 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (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 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @cairolover)

@orizi orizi enabled auto-merge January 6, 2025 11:04
@orizi orizi added this pull request to the merge queue Jan 6, 2025
Merged via the queue into starkware-libs:main with commit 2398bb5 Jan 6, 2025
47 checks passed
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.

4 participants