- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
Suggests that code using .and_then() to take an Option and return an Option should use .map instead, which is meant for this purpose.
Categories (optional)
- Kind:
clippy::style
Advantages
Using .map
in this instance is less verbose and more semantically clear than the alternative. This is what .map
is for; .and_then
is more general and thus it is less obvious what's happening.
Drawbacks
None.
Example
let vector = vec![1, 2, 3]; let maybe: Option<i32> = vector.get(1).and_then(|x| Some(x - 1));
Could be written as:
let vector = vec![1, 2, 3]; let maybe: Option<i32> = vector.get(1).map(|x| x - 1);
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints