Result
extension Result
-
Returns the associated value if the result is a success,
nilotherwise.Declaration
Swift
var success: Success? { get } -
Returns the associated error value if the result is a failure,
nilotherwise.Declaration
Swift
var failure: Failure? { get } -
Evaluates the specified closure when the
Resultis a success, passing the unwrapped value as a parameter.Use the
tryMapmethod with a closure that may throw an error. For example:let possibleData: Result<Data, Error> = .success(Data(...)) let possibleObject = possibleData.tryMap { try JSONSerialization.jsonObject(with: $0) }Declaration
Swift
func tryMap<NewSuccess>(_ transform: (Success) throws -> NewSuccess) -> Result<NewSuccess, Error>Parameters
transformA closure that takes the success value of the instance.
Return Value
A
Resultcontaining the result of the given closure. If this instance is a failure, returns the same failure. -
Evaluates the specified closure when the
Resultis a failure, passing the unwrapped error as a parameter.Use the
tryMapErrorfunction with a closure that may throw an error. For example:let possibleData: Result<Data, Error> = .success(Data(...)) let possibleObject = possibleData.tryMapError { try someFailableFunction(taking: $0) }Declaration
Swift
func tryMapError<NewFailure>(_ transform: (Failure) throws -> NewFailure) -> Result<Success, Error> where NewFailure : ErrorParameters
transformA throwing closure that takes the error of the instance.
Return Value
A
Resultinstance containing the result of the transform. If this instance is a success, returns the same success.
View on GitHub
Install in Dash
Result Extension Reference