Result

public enum Result

A type that represents either a wrapped value or an error, representing the possible return values of a throwing function.

  • Any error.

    Declaration

    Swift

    public typealias Failure = Error
  • The success value, stored as Value.

    Declaration

    Swift

    case success(Success)
  • The failure value, stored as any error.

    Declaration

    Swift

    case failure(Failure)
  • Declaration

    Swift

    @inlinable
    public init(left error: Failure)
  • Declaration

    Swift

    @inlinable
    public init(right value: Success)
  • Declaration

    Swift

    @inlinable
    public init(catching body: () throws -> Success)
  • Declaration

    Swift

    @inlinable
    public func get() throws -> Success
  • Evaluates the transform for a success result, passing its unwrapped value as the parameter, to derive a new value.

    Use the map method with a closure that produces a new value.

    Declaration

    Swift

    public func map<NewSuccess>(_ transform: (Success) -> NewSuccess) -> Task<NewSuccess>.Result
  • Evaluates the transform for a failure result, passing the unwrapped error as the parameter, to derive a new value.

    Use the mapError method with a closure that produces a new value.

    Declaration

    Swift

    public func mapError(_ transform: (Failure) -> Error) -> Task<Success>.Result
  • Evaluates the transform for a success result, passing its unwrapped value as the parameter, to derive a new result.

    Use flatMap with a closure that itself returns a result.

    Declaration

    Swift

    public func flatMap<NewSuccess>(_ transform: (Success) -> Task<NewSuccess>.Result) -> Task<NewSuccess>.Result
  • Evaluates the transform for a failure result, passing the unwrapped error as the parameter, to derive a new result.

    Use the flatMapError with a closure that itself returns a result.

    Declaration

    Swift

    public func flatMapError(_ transform: (Failure) -> Task<Success>.Result) -> Task<Success>.Result
  • Creates an instance storing a successful value.

    Declaration

    Swift

    @inlinable
    public init(success value: @autoclosure() throws -> Success)
  • Creates an instance storing an error describing the failure.

    Declaration

    Swift

    @inlinable
    public init(failure error: Failure)
  • Create an exclusive success/failure state derived from two optionals, in the style of Cocoa completion handlers.

    Declaration

    Swift

    public init(value: Success?, error: Failure?)
  • Creates the success value.

    Declaration

    Swift

    @inlinable
    public init()