Skip to content

Tracking issue for Result::map_or_else #53268

Closed

Description

@Boscop

Result should also have map_or_else(), like Option (but the closure for the else case should also get the Err as argument, like with unwrap_or_else).

Both Option and Result have unwrap_or_else and unwrap_or, so they should also both have map_or_else.

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Aug 29, 2018
  2. changed the title [-]Result should also have map_or_else(), like Option[/-] [+]Tracking issue for Result::map_or_else[/+] on Aug 29, 2018
  3. withoutboats commented on Aug 29, 2018

    @withoutboats
    Contributor

    Implemented in #53777

  4. added a commit that references this issue on Sep 12, 2018
  5. liigo commented on Sep 21, 2018

    @liigo
    Contributor

    I think its parameters should be changed
    from
    fn map_or_else(self, fallback: F, map: M)
    to
    fn map_or_else(self, map: M, fallback: F)

  6. rpjohnst commented on Sep 23, 2018

    @rpjohnst
    Contributor

    It would also be good to have Result::map_or.

  7. Boscop commented on Sep 28, 2018

    @Boscop
    Author

    @liigo Yes, having the fallback as second argument makes more logical sense because it mirrors the if else structure, but this would be a breaking change now :(

  8. Emerentius commented on Oct 13, 2018

    @Emerentius
    Contributor

    @Boscop That's not an issue because it's still unstable. In most cases the error is of a different type than the value and it would cause a compile time error, anyway.

  9. Boscop commented on Oct 15, 2018

    @Boscop
    Author

    @Emerentius I agree that having the ok handler as first arg would make more sense, but I'm not sure how we can change it now.. map_or_else's arg order was chosen to be consistent with map_or. We would have to change the order for both then. I guess you'd have to do a RFC to suggest changing this.

  10. Emerentius commented on Oct 15, 2018

    @Emerentius
    Contributor

    map_or was flipped from the obvious order so that the typically short default case would be in front of the potentially long closure. Breaking consistenty with that is less troublesome than the map_or_else precedent from Option which is stable, already.
    Looks like we're stuck with it…

  11. traviscross commented on Oct 25, 2018

    @traviscross
    Contributor

    Look on the bright side. The original ergonomic argument that the typically longer closure should be at the end is still compelling and provides a reasonable basis for making consistent decisions about this sort of thing.

    To second what was mentioned above, it would make a lot of sense to add Result::map_or at the same time.

  12. ivanbakel commented on Dec 1, 2018

    @ivanbakel
    Contributor

    Is there any reason this shouldn't just be the tracking issue for map_or as well? To me, it seems like they can fall under the same feature flag (even if it won't be as accurately named anymore).

  13. jethrogb commented on Dec 24, 2018

    @jethrogb
    Contributor

    Seconding map_or request

  14. tesuji commented on Nov 11, 2019

    @tesuji
    Contributor

    #66292 is adding map_or. Feedback welcomed.

  15. KatsuoRyuu commented on Nov 12, 2019

    @KatsuoRyuu

    I'm sorry but this implementation of map_or_else is incredibly annoying as it differs from Option.
    When the original issue says:

    Result should also have map_or_else(), like Option (but the closure for the else case should also >get the Err as argument, like with unwrap_or_else).

    Both Option and Result have unwrap_or_else and unwrap_or, so they should also both have >map_or_else.

    and the parameters are then switched, is mildly said absurd! - keep things consistent!

  16. mathstuf commented on Nov 12, 2019

    @mathstuf
    Contributor

    Oof. Indeed. Not only are they switched from Option, but they're backwards from the name too. I really hope it's not too late. Does it need a new feature gate name or is that considered "nightly problems" too?

  17. tesuji commented on Nov 12, 2019

    @tesuji
    Contributor

    Stabilization PR in #66322

  18. added a commit that references this issue on Nov 24, 2019
    7d761fe
  19. cdbattags commented on Jan 31, 2020

    @cdbattags

    Looks like this is released with 1.41 but the order flip is really quite a pain.

    Any precedent for why error first?

  20. lo48576 commented on Jan 31, 2020

    @lo48576
    Contributor

    @cdbattags Seems described in the first comment #53268 (comment).
    I think it is "ok second" rather than "error first", similar to Option::map_or_else.

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

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions