-
Notifications
You must be signed in to change notification settings - Fork 550
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): add map
methods to Result
#6932
Conversation
map
methods to Result
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 all commit messages.
Reviewable status: 0 of 2 files reviewed, all discussions resolved
a discussion (no related file):
@TomerStarkware for 2nd eye.
@eni for doc 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, all discussions resolved
a discussion (no related file):
Previously, orizi wrote…
@TomerStarkware for 2nd eye.
@eni for doc 2nd eye.
sorry - wrong eni @enitrat
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 @cairolover and @orizi)
corelib/src/result.cairo
line 615 at r2 (raw file):
/// /// let x: Result<_, ByteArray> = Result::Err("bar"); /// assert!(x.map_or(42, |v: ByteArray| v.len()) == 42);
Suggestion:
/// let x: Result<ByteArray, ByteArray> = Result::Ok("foo");
/// assert!(x.map_or(42, |v: ByteArray| v.len()) == 3);
///
/// let x: Result<ByteArray, ByteArray> = Result::Err("bar");
/// assert!(x.map_or(42, |v: ByteArray| 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, 1 unresolved discussion (waiting on @cairolover and @orizi)
corelib/src/result.cairo
line 644 at r2 (raw file):
/// let x : Result<ByteArray, ByteArray> = Result::Err("bar"); /// assert!(x.map_or_else(|e: ByteArray| k * 2, |v: ByteArray| v.len()) == 42); /// ```
Suggestion:
/// let x : Result<ByteArray, _> = Result::Ok("foo");
/// assert!(x.map_or_else(|e: ByteArray| k * 2, |v: ByteArray| v.len()) == 3);
///
/// let x : Result<_, ByteArray> = Result::Err("bar");
/// assert!(x.map_or_else(|e: ByteArray| k * 2, |v: ByteArray| 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, 1 unresolved discussion (waiting on @enitrat and @orizi)
corelib/src/result.cairo
line 644 at r2 (raw file):
/// let x : Result<ByteArray, ByteArray> = Result::Err("bar"); /// assert!(x.map_or_else(|e: ByteArray| k * 2, |v: ByteArray| v.len()) == 42); /// ```
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, all discussions resolved (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.
Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @cairolover)
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 @cairolover)
corelib/src/result.cairo
line 681 at r3 (raw file):
/// ``` fn map_err<F, O, +Drop<O>, +core::ops::FnOnce<O, (E,)>[Output: F]>( self: Result<T, E>, op: O,
make the parameters name consistent with the rest of functions
Suggestion:
fn map_err<F, U, +Drop<F>, +core::ops::FnOnce<F, (E,)>[Output: U]>(
self: Result<T, E>, f: F,
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 @TomerStarkware)
corelib/src/result.cairo
line 681 at r3 (raw file):
Previously, TomerStarkware wrote…
make the parameters name consistent with the rest of functions
Error types - E -> F
Return types - T -> U
Function types - F
(fn), O
(op)
There's a "conflict" here between F
as the second candidate for error type and F
the function. Thus O
and op
seems more logical to me than assigning U
to an Error type
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: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)
corelib/src/result.cairo
line 681 at r3 (raw file):
Previously, cairolover (cairolover) wrote…
Error types -
E -> F
Return types -T -> U
Function types -F
(fn),O
(op)There's a "conflict" here between
F
as the second candidate for error type andF
the function. ThusO
andop
seems more logical to me than assigningU
to an Error type
Done.
used G
for the second error type
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 1 of 1 files at r4, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @cairolover)
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 all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @cairolover)
corelib/src/result.cairo
line 682 at r4 (raw file):
fn map_err<F, G, +Drop<F>, +core::ops::FnOnce<F, (E,)>[Output: G]>( self: Result<T, E>, f: F, ) -> Result<T, G> {
let's stick to rust's signature - and more so to the first param being the output type.
Suggestion:
fn map_err<F, O, +Drop<F>, +core::ops::FnOnce<O, (E,)>[Output: F]>(
self: Result<T, E>, op: O,
) -> Result<T, F> {
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 (commit messages unreviewed), 1 unresolved discussion (waiting on @orizi)
corelib/src/result.cairo
line 682 at r4 (raw file):
Previously, orizi wrote…
let's stick to rust's signature - and more so to the first param being the output type.
Done.
This reverts commit 796bf6f.
bd307f9
to
9f32ee8
Compare
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 1 of 1 files at r5, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @cairolover)
Adds
map
,map_or
,map_or_else
andmap_err
toResult
.