-
Notifications
You must be signed in to change notification settings - Fork 598
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
feat(corelib): OptionTrait boolean operators #6936
Conversation
There was a problem hiding this 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
There was a problem hiding this 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 and @orizi)
There was a problem hiding this 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 and @orizi)
There was a problem hiding this 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, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @julio4)
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
, andxor
methods take another [Option
] as input, and produce an [Option
] as output. Only theand
method can produce an [Option<U>
] value having a different inner typeU
than [Option<T>
].and
None
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)
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
andor_else
methods take a function as input, andonly evaluate the function when they need to produce a new value. Only
the
and_then
method can produce an [Option<U>
] value having adifferent inner type
U
than [Option<T>
].and_then
None
None
and_then
Some(x)
x
None
None
and_then
Some(x)
x
Some(y)
Some(y)
or_else
None
None
None
or_else
None
Some(y)
Some(y)
or_else
Some(x)
Some(x)