A value that represents either a success or a failure, including an associated value in each case.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
@frozen enum Result<Success, Failure> where Failure : Error
A value that represents either a success or a failure, including an associated value in each case.
SDK
Framework
@frozen enum Result<Success, Failure> where Failure : Error
case success(Success)
A success, storing a Success
value.
case failure(Failure)
A failure, storing a Failure
value.
Vend results as part of an API when you can’t return errors synchronously.
Call the initializer that wraps a throwing expression when you need to serialize or memoize the result.
init(catching: () -> Success)
Creates a new result by evaluating a throwing closure, capturing the returned value as a success, or any thrown error as a failure.
func get() -> Success
Returns the success value as a throwing expression.
func map<NewSuccess>((Success) -> NewSuccess) -> Result<NewSuccess, Failure>
Returns a new result, mapping any success value using the given transformation.
func mapError <NewFailure>((Failure) -> NewFailure) -> Result<Success, NewFailure>
Returns a new result, mapping any failure value using the given transformation.
func flatMap <NewSuccess>((Success) -> Result<NewSuccess, Failure>) -> Result<NewSuccess, Failure>
Returns a new result, mapping any success value using the given transformation and unwrapping the produced result.
func flatMapError <NewFailure>((Failure) -> Result<Success, NewFailure>) -> Result<Success, NewFailure>
Returns a new result, mapping any failure value using the given transformation and unwrapping the produced result.
struct Result.Publisher
A Combine publisher that publishes a result and then finishes normally, or fails without publishing any elements.
func hash(into: inout Hasher)
Hashes the essential components of this value by feeding them into the given hasher.
static func == (Result<Success, Failure>, Result<Success, Failure>) -> Bool
Returns a Boolean value indicating whether two values are equal.
protocol Error
A type representing an error value that can be thrown.