ResultUtil
public enum ResultUtil
A set of convenience methods for manipulating the Result type.
-
Evaluates the given transform closures to create a single output value.
Declaration
Swift
public static func match<Success, Failure: Error, Output>( result: Result<Success, Failure>, onSuccess: (Success) -> Output, onFailure: (Failure) -> Output) -> OutputParameters
resultThe input
Resultvalue.onSuccessA closure that transforms the success value.
onFailureA closure that transforms the error value.
Return Value
A single
Outputvalue returned by either theonSuccessblock oronFailureblock. -
Evaluates the given transform closures, converting the success value with the use of a folder to create a single output value.
Declaration
Swift
public static func matchSuccess<Success, Failure: Error, Output>( result: Result<Success, Failure>, with folder: (Success?) -> Output) -> OutputParameters
resultThe input
Resultvalue.folderA closure that takes an optional value of the result. If the
resultresolves to.success, it takes the unwrapped value. Otherwise, it takesnil.Return Value
A single
Outputvalue returned by thefolder. -
Evaluates the given transform closures, converting the failure value with the use of a folder to create a single output value.
Declaration
Swift
public static func matchFailure<Success, Failure: Error, Output>( result: Result<Success, Failure>, with folder: (Error?) -> Output) -> OutputParameters
resultThe input
Resultvalue.folderA closure that takes an optional value of the result. If the
resultresolves to.failure, it takes the unwrapped error. Otherwise, it takesnil.Return Value
A single
Outputvalue returned by thefolder. -
Evaluates the given transform closures, converting the result pair with the use of a folder to create a single output value.
Declaration
Swift
public static func match<Success, Failure: Error, Output>( result: Result<Success, Failure>, with folder: (Success?, Error?) -> Output) -> OutputParameters
resultThe input
Resultvalue.folderA closure that takes a tuple consisted by two optional values. The first value in the tuple is the unwrapped value if
resultresolves to.success. The second value is the unwrapped value ifresultresolves to.failure.Return Value
A single
Outputvalue returned by thefolder.
View on GitHub
ResultUtil Enumeration Reference