Result
public enum Result<V>
Wraps result of throwing code and allows to map embedded value
-
Resulted in error
Declaration
Swift
case error(Error)
-
Successfully aquired a value
Declaration
Swift
case value(V)
-
Init with unsafe code
let result = Result<V> { // Your unsafe code, that results either in value of type V or in error }
Declaration
Swift
public init(_ unsafe: () throws -> V)
-
Convinience init with unsafe code
let result = Result<V> ( // Your unsafe code, that results either in value of type V or in error )
Declaration
Swift
public init(_ unsafe: @autoclosure () throws -> V)
-
Wraps value in Result
Declaration
Swift
public static func pure(_ value: V) -> Result<V>
-
Wrap some throwing function from
U -> V
inU -> Result<V>
functionDeclaration
Swift
public static func wrap<U>(_ function: @escaping (U) throws -> V) -> ((U) -> Result)
-
Get unsafe execution back, in case if you want to use do … catch after all
Declaration
Swift
public func unwrap() throws -> V
-
Unwrap value as optional
Declaration
Swift
public var value: V?
-
Unwrap error as optional
Declaration
Swift
public var error: Error?
-
If there’s no error, perform function with value and return wrapped result
Declaration
Swift
public func map<U>(_ transform: (V) -> U) -> Result<U>
-
Performs transformation over value of Result.
Declaration
Swift
public func forEach(_ transform: (V) -> Void)
-
If there’s no error, perform function that may yield Result with value and return wrapped result
Declaration
Swift
public func flatMap<U>(_ transform: (V) -> Result<U>) -> Result<U>