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

Option<T> `map_or` and `map_or_else` type is inconsistent with `map` #27422

Closed
FuGangqiang opened this Issue Jul 31, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@FuGangqiang
Copy link
Contributor

FuGangqiang commented Jul 31, 2015

map method type is

fn map<U, F>(self, f: F) -> Option<U> 
    where F: FnOnce(T) -> U

map_or method type is

fn map_or<U, F>(self, default: U, f: F) -> U 
    where F: FnOnce(T) -> U

map_or_else method type is

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

map : Option<T> -> Option<U> is ok,
but map_or and map_or_else : Option<T>->U ,why not return Option<U> type

@FuGangqiang FuGangqiang changed the title Option<T> `map_or` and `map_or_else` type is not inconsistent with `map` Option<T> `map_or` and `map_or_else` type is inconsistent with `map` Jul 31, 2015

@abonander

This comment has been minimized.

Copy link
Contributor

abonander commented Jul 31, 2015

What use would it be to return Option<U> if you know it's always going to be Some(U)? Both map_or and map_or_else are given a default to return if self is None. Their design parallels unwrap_or() and unwrap_or_else().

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 31, 2015

Yes as @cybergeek94 these are just shorthands for .map(...).unwrap_or(...), so the signatures aren't exactly in alignment. These functions are also stable today, so their signatures won't be changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.