Skip to content

Commit

Permalink
Add use case with Never
Browse files Browse the repository at this point in the history
  • Loading branch information
wzso committed Jul 17, 2023
1 parent d75a099 commit 2f84c9a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions content/post/swift-result.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,19 @@ extension Result where Failure == Error {
/// - Parameter body: A throwing closure to evaluate.
public init(catching body: () throws -> Success)
}
```

# Use with `Never`

Since `Never` conforms to `Error` protocol, it can be used as the failure value type in `Result`.

```swift
let result: Result<Int, Never> = .success(100)

switch result {
case .success(let number):
print(number)
//case .failure(_): // compiler won't yell at you without the failure case.
// break
}
```

0 comments on commit 2f84c9a

Please sign in to comment.