Skip to content

Documentation on Result::map_or_else uses very unfortunate wording #88195

Closed
@orlp

Description

@orlp
Contributor

The type signature of Result::map_or_else:

pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U where
    F: FnOnce(T) -> U,
    D: FnOnce(E) -> U, 

Note how default is the function that gets applied to the Err variant. Then, the docstring (emphasis mine):

Maps a Result<T, E> to U by applying a fallback function to a contained Err value, or a default function to a contained Ok value.

I think this is a very unfortunate choice of words and should be changed.

Activity

jyn514

jyn514 commented on Aug 21, 2021

@jyn514
Member
added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
T-libsRelevant to the library team, which will review and decide on the PR/issue.
on Aug 21, 2021
orlp

orlp commented on Aug 21, 2021

@orlp
ContributorAuthor

I could, but I think I'd prefer to bikeshed a bit first as to how it should be described.

MightyPork

MightyPork commented on Aug 22, 2021

@MightyPork

To me these functions are so confusing that I practically never use them, the arguments are in the wrong order ... as repeatedly noted in both the tracking issue and stabilization PR that added it. It can't be changed, of course :/

I rather like the way it's documented in the corresponding method on Option: https://doc.rust-lang.org/std/option/enum.Option.html#method.map_or_else

mdsn

mdsn commented on Aug 27, 2021

@mdsn
Contributor

How about

Maps a Result<T, E> to U by applying function f to a contained Ok value, or by applying default to a contained Err value.

It explains in the same order as the function name (ok_or_else) and doesn't overload the meaning of "default" in the context of the unfortunate function argument.

orlp

orlp commented on Sep 9, 2021

@orlp
ContributorAuthor

Made a pull request using @mdsn 's suggestion, only replacing "applying default" with "applying function default" to be consistent with the earlier part of the sentence.

added 2 commits that reference this issue on Oct 7, 2021

Rollup merge of rust-lang#88772 - orlp:result-map-or-else-docfix, r=y…

899250e

Rollup merge of rust-lang#88772 - orlp:result-map-or-else-docfix, r=y…

837a032
added a commit that references this issue on Oct 8, 2021

Rollup merge of rust-lang#88772 - orlp:result-map-or-else-docfix, r=y…

2b6d7f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @orlp@mdsn@MightyPork@jyn514

      Issue actions

        Documentation on `Result::map_or_else` uses very unfortunate wording · Issue #88195 · rust-lang/rust