Skip to content

Commit

Permalink
Add a section about destructuring (#114).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Oct 21, 2024
1 parent 77fc60a commit e50bfd0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,14 @@ What about expectations? Sometimes, you make a fallible function call that shoul
U8.min.incremented().unwrap("precondition") // must not fail
U8.min.incremented().unchecked("assertion") // must not fail, must go brrr
```

#### Destructuring: `value`, `error`, `components()`

While this model strives to streamline the error-handling process, perhaps you want to take the wheel. Sure, have fun! You can read and write to its value and error fields directly. Alternatively, you may destructure the pair by invoking the consuming `components()` method. Here's the short version of it.

```swift
var pair = Fallible("Hello")
pair.value.append(", World")
pair.error.toggle()
let (value, error) = pair.components()
```

0 comments on commit e50bfd0

Please sign in to comment.