-
Notifications
You must be signed in to change notification settings - Fork 531
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::map_or, OptionTrait::map_or_else #6935
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, 2 unresolved discussions (waiting on @julio4)
corelib/src/option.cairo
line 356 at r2 (raw file):
/// or applies a function to the contained value (if any). /// /// Arguments passed to `map_or` are eagerly evaluated; if you are passing
I don't believe this applies
corelib/src/option.cairo
line 368 at r2 (raw file):
/// /// let x: Option<ByteArray> = Option::None; /// assert_eq!(x.map_or(42, |v| v.len()), 42);
This does not compile
Code quote:
/// assert_eq!(Option::Some("foo").map_or(42, |v| v.len()), 3);
///
/// let x: Option<ByteArray> = Option::None;
/// assert_eq!(x.map_or(42, |v| v.len()), 42);
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, 2 unresolved discussions (waiting on @enitrat)
corelib/src/option.cairo
line 356 at r2 (raw file):
Previously, enitrat (Mathieu) wrote…
I don't believe this applies
Is it different than rust?
corelib/src/option.cairo
line 368 at r2 (raw file):
Previously, enitrat (Mathieu) wrote…
This does not compile
Done.
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 r3, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @enitrat and @julio4)
a discussion (no related file):
awaiting the other discussion.
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: all files reviewed, 3 unresolved discussions (waiting on @julio4)
corelib/src/option.cairo
line 356 at r2 (raw file):
Previously, julio4 (Julio) wrote…
Is it different than rust?
actually, no, you're right
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: all files reviewed, 2 unresolved discussions (waiting on @julio4 and @orizi)
corelib/src/option.cairo
line 368 at r2 (raw file):
Previously, julio4 (Julio) wrote…
Done.
@orizi shouldn't v
be automatically inferred as a ByteArray
here?
Previously, enitrat (Mathieu) wrote…
Would love to know as well how the trait bounds inference is currently done |
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 @orizi)
a discussion (no related file):
Previously, orizi wrote…
awaiting the other discussion.
Done.
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 r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @julio4)
corelib/src/option.cairo
line 368 at r2 (raw file):
Previously, julio4 (Julio) wrote…
Would love to know as well how the trait bounds inference is currently done
it should - will make sure to check why it doesn't next week. @TomerStarkware
in general - trait bounds are adding 2 things:
- An additional assertion that the types match in the call context.
- Makes the types be used as the exact same type in the function context.
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: all files reviewed, 1 unresolved discussion (waiting on @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: complete! all files reviewed, all discussions resolved (waiting on @julio4)
OptionTrait::map_or
Returns the provided default result (if none), or applies a function to the contained value (if any).
Example
OptionTrait::map_or_else
Computes a default function result (if none), or applies a different function to the contained value (if any).
Example