Skip to content

Commit 01b3ebd

Browse files
authored
Update option_result.md
1 parent 658c6c2 commit 01b3ebd

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/error/multiple_error_types/option_result.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ fn main() {
2828
```
2929

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

3433
```rust,editable
3534
use std::num::ParseIntError;
@@ -39,7 +38,7 @@ fn double_first(vec: Vec<&str>) -> Result<Option<i32>, ParseIntError> {
3938
first.parse::<i32>().map(|n| 2 * n)
4039
});
4140
42-
opt.map_or(Ok(None), |r| r.map(Some))
41+
opt.transpose()
4342
}
4443
4544
fn main() {

0 commit comments

Comments
 (0)