@@ -20,15 +20,15 @@ public enum Result<Success, Failure: Error> {
20
20
/// A failure, storing a `Failure` value.
21
21
case failure( Failure )
22
22
23
- /// Evaluates the given transform closure when this `Result` instance is
24
- /// `.success`, passing the value as a parameter.
23
+ /// Evaluates the given closure when this `Result` instance is `.success`,
24
+ /// passing the success value as a parameter.
25
25
///
26
26
/// Use the `map` method with a closure that returns a non-`Result` value.
27
27
///
28
- /// - Parameter transform: A closure that takes the successful value of the
28
+ /// - Parameter transform: A closure that takes the success value of the
29
29
/// instance.
30
- /// - Returns: A new `Result` instance with the result of the transform, if
31
- /// it was applied .
30
+ /// - Returns: A `Result` instance with the result of evaluating the given
31
+ /// closure as the new success value if this instance is `.success` .
32
32
public func map< NewSuccess> (
33
33
_ transform: ( Success ) -> NewSuccess
34
34
) -> Result < NewSuccess , Failure > {
@@ -40,16 +40,16 @@ public enum Result<Success, Failure: Error> {
40
40
}
41
41
}
42
42
43
- /// Evaluates the given transform closure when this `Result` instance is
44
- /// `.failure`, passing the error as a parameter.
43
+ /// Evaluates the given closure when this `Result` instance is `.failure`,
44
+ /// passing the failure value as a parameter.
45
45
///
46
46
/// Use the `mapError` method with a closure that returns a non-`Result`
47
47
/// value.
48
48
///
49
49
/// - Parameter transform: A closure that takes the failure value of the
50
50
/// instance.
51
- /// - Returns: A new `Result` instance with the result of the transform, if
52
- /// it was applied .
51
+ /// - Returns: A `Result` instance with the result of evaluating the given
52
+ /// closure as the new failure value if this instance is `.failure` .
53
53
public func mapError< NewFailure> (
54
54
_ transform: ( Failure ) -> NewFailure
55
55
) -> Result < Success , NewFailure > {
@@ -61,13 +61,13 @@ public enum Result<Success, Failure: Error> {
61
61
}
62
62
}
63
63
64
- /// Evaluates the given transform closure when this `Result` instance is
65
- /// `.success`, passing the value as a parameter and flattening the result .
64
+ /// Evaluates the given closure when this `Result` instance is `.success`,
65
+ /// passing the success value as a parameter.
66
66
///
67
- /// - Parameter transform: A closure that takes the successful value of the
67
+ /// - Parameter transform: A closure that takes the success value of the
68
68
/// instance.
69
- /// - Returns: A new `Result` instance, either from the transform or from
70
- /// the previous error value .
69
+ /// - Returns: A`Result` instance, either from the closure or the previous
70
+ /// `.failure` .
71
71
public func flatMap< NewSuccess> (
72
72
_ transform: ( Success ) -> Result < NewSuccess , Failure >
73
73
) -> Result < NewSuccess , Failure > {
@@ -79,13 +79,13 @@ public enum Result<Success, Failure: Error> {
79
79
}
80
80
}
81
81
82
- /// Evaluates the given transform closure when this `Result` instance is
83
- /// `.failure`, passing the error as a parameter and flattening the result .
82
+ /// Evaluates the given closure when this `Result` instance is `.failure`,
83
+ /// passing the failure value as a parameter.
84
84
///
85
- /// - Parameter transform: A closure that takes the error value of the
85
+ /// - Parameter transform: A closure that takes the failure value of the
86
86
/// instance.
87
- /// - Returns: A new `Result` instance, either from the transform or from
88
- /// the previous success value .
87
+ /// - Returns: A `Result` instance, either from the closure or the previous
88
+ /// `. success` .
89
89
public func flatMapError< NewFailure> (
90
90
_ transform: ( Failure ) -> Result < Success , NewFailure >
91
91
) -> Result < Success , NewFailure > {
@@ -97,10 +97,10 @@ public enum Result<Success, Failure: Error> {
97
97
}
98
98
}
99
99
100
- /// Attempts to get the ` success` value as a throwing expression.
100
+ /// Get the success value as a throwing expression.
101
101
///
102
- /// - Returns: The success value, if the instance is a success.
103
- /// - Throws: The failure value, if the instance is a failure.
102
+ /// - Returns: The success value, if the instance is `. success` .
103
+ /// - Throws: The failure value, if the instance is `. failure` .
104
104
public func get( ) throws -> Success {
105
105
switch self {
106
106
case let . success( success) :
@@ -112,20 +112,20 @@ public enum Result<Success, Failure: Error> {
112
112
}
113
113
114
114
extension Result where Failure == Swift . Error {
115
- /// Create an instance by capturing the output of a throwing closure.
115
+ /// Create an instance by evaluating a throwing closure, capturing the
116
+ /// returned value as a `.success` or any thrown error as `.failure`.
116
117
///
117
118
/// - Parameter catching: A throwing closure to evaluate.
118
119
@_transparent
119
120
public init ( catching body: ( ) throws -> Success ) {
120
121
do {
121
- let value = try body ( )
122
- self = . success( value)
122
+ self = . success( try body ( ) )
123
123
} catch {
124
124
self = . failure( error)
125
125
}
126
126
}
127
127
}
128
128
129
- extension Result : Equatable where Success : Equatable , Failure : Equatable { }
129
+ extension Result : Equatable where Success: Equatable , Failure: Equatable { }
130
130
131
- extension Result : Hashable where Success : Hashable , Failure : Hashable { }
131
+ extension Result : Hashable where Success: Hashable , Failure: Hashable { }
0 commit comments