-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
use composition in std::option #9355
Comments
I'm all for reducing the API. I'm a bit worried about the naming though, as I'm not aware of consensus being reached on #7887. And as @blake2-ppc pointed out in IRC, |
There's not really any consensus about any of the names and the discussion would need to start over if there were 1/3 of the number of methods. I'll try to keep the names as close to what they already are though. |
1+ for better composability! |
This looks pretty compelling to me. If we did this, then renaming |
How could this pattern be applied to other containers? |
@brson: In general, the The only algorithm with a specific need is |
|
While I love composability and think most people will use
How can we resolve the conflict between the |
Seems to me like @thestinger: Would it be possible to have more an one You'd then for example implement all three for vector, but only |
erickt, with map being either of these (with pseudocode):
It does seem consistent to me. I don't see the need to treat Option as an Iterable or container itself, it is a far more basic building block than that. |
@blake2-ppc The idea behind the HOWEVER, I just realized we can just solve this in an easy way: |
My suggestion was: Option should not be Iterable or an Iterator. |
I agree with @blake2-ppc. Having Option be an Iterable or Iterator just feels weird. If I call |
Implemented. |
Fix typos changelog: none
Rather than having 3 versions of every utility (get, map, chain, etc.), we can have a single by-value version.
Conversion to
Option<&T>
andOption<&mut T>
fromOption<T>
can be composed with the regular combinators. References are first-class values, so there's no need to have extra methods for them.map_move(...)
->map(...)
map(...)
->as_imm().map(...)
map_mut(...)
->as_mut().map(...)
map_move_default(...)
->map_default(...)
map_default(...)
->as_imm().map_default(...)
map_mut_default(...)
->as_mut().map_default(...)
and_then(...)
->and_then(...)
and_then_ref(...)
->as_imm().and_then(...)
and_then_mut_ref(...)
->as_mut().and_then(...)
unwrap()
->unwrap()
get_ref()
->as_imm().unwrap()
get_mut_ref()
->as_mut().unwrap()
The text was updated successfully, but these errors were encountered: