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

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

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);

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.

3 participants