Skip to content

use composition in std::option #9355

Closed
Closed
@thestinger

Description

@thestinger

Rather than having 3 versions of every utility (get, map, chain, etc.), we can have a single by-value version.

Conversion to Option<&T> and Option<&mut T> from Option<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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions