Skip to content

Commit

Permalink
update original
Browse files Browse the repository at this point in the history
  • Loading branch information
funkill committed Jul 12, 2024
1 parent 48a981e commit 1dd3249
Showing 1 changed file with 2 additions and 3 deletions.
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 1dd3249

Please sign in to comment.