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) -> Output
Parameters
result
The input
Result
value.onSuccess
A closure that transforms the success value.
onFailure
A closure that transforms the error value.
Return Value
A single
Output
value returned by either theonSuccess
block oronFailure
block. -
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) -> Output
Parameters
result
The input
Result
value.folder
A closure that takes an optional value of the result. If the
result
resolves to.success
, it takes the unwrapped value. Otherwise, it takesnil
.Return Value
A single
Output
value 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) -> Output
Parameters
result
The input
Result
value.folder
A closure that takes an optional value of the result. If the
result
resolves to.failure
, it takes the unwrapped error. Otherwise, it takesnil
.Return Value
A single
Output
value 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) -> Output
Parameters
result
The input
Result
value.folder
A closure that takes a tuple consisted by two optional values. The first value in the tuple is the unwrapped value if
result
resolves to.success
. The second value is the unwrapped value ifresult
resolves to.failure
.Return Value
A single
Output
value returned by thefolder
.