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 boolean operators #6936

Merged
merged 4 commits into from
Dec 28, 2024

Conversation

julio4
Copy link
Contributor

@julio4 julio4 commented Dec 26, 2024

Boolean operators

These methods treat the [Option] as a boolean value, where [Some] acts like [true] and [None] acts like [false]. There are two categories of these methods: ones that take an [Option] as input, and ones that take a function as input (to be lazily evaluated).

The and, or, and xor methods take another [Option] as input, and produce an [Option] as output. Only the and method can produce an [Option<U>] value having a different inner type U than [Option<T>].

method self input output
and None (ignored) None
and Some(x) None None
and Some(x) Some(y) Some(y)
or None None None
or None Some(y) Some(y)
or Some(x) (ignored) Some(x)
xor None None None
xor None Some(y) Some(y)
xor Some(x) None Some(x)
xor Some(x) Some(y) None

The and_then and or_else methods take a function as input, and
only evaluate the function when they need to produce a new value. Only
the and_then method can produce an [Option<U>] value having a
different inner type U than [Option<T>].

method self function input function result output
and_then None (not provided) (not evaluated) None
and_then Some(x) x None None
and_then Some(x) x Some(y) Some(y)
or_else None (not provided) None None
or_else None (not provided) Some(y) Some(y)
or_else Some(x) (not provided) (not evaluated) Some(x)

@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.

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


a discussion (no related file):
@enitat @TomerStarkware 2nd eye

Copy link
Collaborator

@TomerStarkware TomerStarkware 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: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @julio4 and @orizi)

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: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @julio4 and @orizi)

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 r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @julio4)

@orizi orizi added this pull request to the merge queue Dec 28, 2024
Merged via the queue into starkware-libs:main with commit 8236b95 Dec 28, 2024
47 checks passed
@julio4 julio4 deleted the feat/option_boolean_operators branch December 28, 2024 12:06
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