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): OptionTrait::filter #7108

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

hudem1
Copy link
Contributor

@hudem1 hudem1 commented Jan 17, 2025

I suggest the addition of OptionTrait::filter method that:

returns [None] if the option is [None], otherwise calls predicate with the wrapped value and returns:

  • [Some(t)] if predicate returns true (where t is the wrapped value)
  • [None] if predicate returns false.
let is_even = |x: u32| -> bool {
    x % 2 == 0
};

assert!(Option::None.filter(is_even) == Option::None);
assert!(Option::Some(3).filter(is_even) == Option::None);
assert!(Option::Some(4).filter(is_even) == Option::Some(4));

@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 2 of 2 files at r1.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @hudem1)


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

    }

    fn filter<P, +core::ops::FnOnce<P, (T,)>[Output: bool], +Drop<T>, +Drop<P>, +Copy<T>>(

Suggestion:

    fn filter<P, +core::ops::FnOnce<P, (@T,)>[Output: bool], +Destruct<T>, +Destruct<P>>(

Copy link
Contributor Author

@hudem1 hudem1 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 808 at r1 (raw file):

    }

    fn filter<P, +core::ops::FnOnce<P, (T,)>[Output: bool], +Drop<T>, +Drop<P>, +Copy<T>>(

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.

:lgtm:

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @hudem1)


a discussion (no related file):
@gilbens-starkware

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 @hudem1)


a discussion (no related file):

Previously, orizi wrote…

@gilbens-starkware

@ilyalesokhin-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:

:lgtm:

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @hudem1)

@orizi orizi added this pull request to the merge queue Jan 20, 2025
Merged via the queue into starkware-libs:main with commit aa2c34d Jan 20, 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