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): add map methods to Result #6932

Merged
merged 5 commits into from
Jan 4, 2025

Conversation

cairolover
Copy link
Contributor

Adds map, map_or, map_or_else and map_err to Result.

@reviewable-StarkWare
Copy link

This change is Reviewable

@cairolover cairolover changed the title feat(corelib): add 'map' methods to 'Result' feat(corelib): add map methods to Result Dec 26, 2024
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 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.

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, all discussions resolved


a discussion (no related file):

Previously, orizi wrote…

@TomerStarkware for 2nd eye.
@eni for doc 2nd eye.

sorry - wrong eni @enitrat

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.

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);

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.

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);
    /// ```

Copy link
Contributor Author

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

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

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.

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,

Copy link
Contributor Author

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

Copy link
Contributor Author

@cairolover cairolover 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: 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 and F the function. Thus O and op seems more logical to me than assigning U to an Error type

Done.
used G for the second error type

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:

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @cairolover)

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 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> {

Copy link
Contributor Author

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

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

5 participants