Skip to content

Commit

Permalink
Merge pull request #1864 from stefnotch/patch-1
Browse files Browse the repository at this point in the history
Update option_result.md
  • Loading branch information
marioidival authored Jul 11, 2024
2 parents 658c6c2 + 01b3ebd commit 89aecb6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/error/multiple_error_types/option_result.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ fn main() {
```

There are times when we'll want to stop processing on errors (like with
[`?`][enter_question_mark]) but keep going when the `Option` is `None`. A
couple of combinators come in handy to swap the `Result` and `Option`.
[`?`][enter_question_mark]) but keep going when the `Option` is `None`. The `transpose` function comes in handy to swap the `Result` and `Option`.

```rust,editable
use std::num::ParseIntError;
Expand All @@ -39,7 +38,7 @@ fn double_first(vec: Vec<&str>) -> Result<Option<i32>, ParseIntError> {
first.parse::<i32>().map(|n| 2 * n)
});
opt.map_or(Ok(None), |r| r.map(Some))
opt.transpose()
}
fn main() {
Expand Down

0 comments on commit 89aecb6

Please sign in to comment.