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() -> SuccessReturns the success value as a throwing expression.
func map<New Success>((Success) -> New Success) -> Result<New Success, Failure>Returns a new result, mapping any success value using the given transformation.
func map Error<New Failure>((Failure) -> New Failure) -> Result<Success, New Failure>Returns a new result, mapping any failure value using the given transformation.
func flat Map<New Success>((Success) -> Result<New Success, Failure>) -> Result<New Success, Failure>Returns a new result, mapping any success value using the given transformation and unwrapping the produced result.
func flat Map Error<New Failure>((Failure) -> Result<Success, New Failure>) -> Result<Success, New Failure>Returns a new result, mapping any failure value using the given transformation and unwrapping the produced result.
struct Result .PublisherA 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>) -> BoolReturns a Boolean value indicating whether two values are equal.
protocol ErrorA type representing an error value that can be thrown.