You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -286,6 +288,28 @@ This proposal adds a type to the standard library and so will affect the ABI onc
286
288
Addition of `Result<Value, Error>` should be future proof against future needs surrounding error handling.
287
289
288
290
## Alternatives considered
291
+
292
+
### Alternative Spellings of `Result<Value, Error>`
293
+
Two alternate spellings were proposed:
294
+
295
+
```swift
296
+
enum Result<Value, Error> {
297
+
casevalue(Value)
298
+
caseerror(Error)
299
+
}
300
+
```
301
+
and
302
+
303
+
```swift
304
+
enum Result<Wrapped, Failure> {
305
+
casevalue(Value)
306
+
caseerror(Error)
307
+
}
308
+
```
309
+
However, these spellings emphasize more of a similarity to `Optional` than seems appropriate. Emphasizing `Result` good/bad, yes/no, success/failure nature seems more inline with the typical usage and meaning of the type. Using `success` and `failure` cases makes that usage completely clear. The `Value`/`Error` generic types appropriately convey the usage of the individual types along the same lines. Ultimately, however, the proposed spelling benefits from the fact that's it's the most common spelling implemented by the Swift community, making it the easiest to drop in and replace existing implementations, as well as benefitting from the current level of community knowledge around the type.
310
+
311
+
### Alternatives to `Result<Value, Error>`
312
+
289
313
- `Result<T>`: A `Result` without a generic error type fits well with the current error design in Swift. However, it prevents the future addition of typed error handling (typed `throws`), as well as locking all `Result` usage into failure types which conform to `Error`.
290
314
291
315
- `Result<T, E: Error>`: A `Result` that constrains its error type to just those types conforming to `Error` allows for fully typed error handling. However, this type is incompatible with current Swift error handling, as it cannot capture unconstrained `Error` values. This would require either casting to a specific error type (commonly `NSError`, which is an anti-pattern) or the addition of a `Error` box type, such as `AnyError`. Additionally, the constraint prevents future growth towards capturing non-`Error` conforming types.
0 commit comments