Fallible

public enum Fallible<Success> : _Fallible

Fallible is an implementation of validation monad. May contain either success value or failure in form of Error.

  • success case of Fallible. Contains success value

    Declaration

    Swift

    case success(Success)
  • failure case of Fallible. Contains failure value (Error)

    Declaration

    Swift

    case failure(Swift.Error)
  • Initializes Fallible with success value

    Declaration

    Swift

    public init(success: Success)

    Parameters

    success

    value to initalize Fallible with

  • Initializes Fallible with failure valie

    Declaration

    Swift

    public init(failure: Swift.Error)

    Parameters

    failure

    error to initalize Fallible with

  • makes fallible with succees

    Declaration

    Swift

    public static func just(_ success: Success) -> Fallible<Success>
  • Transforms the fallible to a fallible of unrelated type Correctness of such transformation is left on our behalf

    Declaration

    Swift

    func staticCast<T>() -> Fallible<T>
  • Transforms the fallible to a fallible of unrelated type Incorrect transformation will result into dynamicCastFailed failure

    Declaration

    Swift

    func dynamicCast<T>() -> Fallible<T>
  • A textual representation of this instance.

    Declaration

    Swift

    public var description: String { get }
  • A textual representation of this instance, suitable for debugging.

    Declaration

    Swift

    public var debugDescription: String { get }
  • Returns success if Fallible has a success value inside. Returns nil otherwise

    Declaration

    Swift

    var success: Success? { get }
  • Returns success if Fallible has a success value inside. Crashes otherwise

    Declaration

    Swift

    var unsafeSuccess: Success! { get }
  • Returns failure if Fallible has a failure value inside. Returns nil otherwise

    Declaration

    Swift

    var failure: Swift.Error? { get }
  • This method is convenient when you want to transfer back to a regular Swift error handling

    Throws

    failure value if Fallible has a failure value inside

    Declaration

    Swift

    func liftSuccess() throws -> Success

    Return Value

    success value if Fallible has a success value inside

  • Executes block if Fallible has success value inside

    Throws

    rethrows an error thrown by the block

    Declaration

    Swift

    func onSuccess(_ block: (_ success: Success) throws -> Void) rethrows

    Parameters

    handler

    handler to execute

    success

    success value of Fallible

  • Executes block if Fallible has failure value inside

    Throws

    rethrows an error thrown by the block

    Declaration

    Swift

    func onFailure(_ block: (_ failure: Swift.Error) throws -> Void) rethrows

    Parameters

    handler

    handler to execute

    failure

    failure value of Fallible

  • Applies transformation to Fallible

    Declaration

    Swift

    func map<T>(_ transform: (_ success: Success) throws -> T) -> Fallible<T>

    Parameters

    transform

    block to apply. A success value returned from block will be a success value of the transformed Fallible. An error thrown from block will be a failure value of a transformed Fallible This block will not be executed if an original Fallible contains a failure. That failure will become a failure value of a transfomed Fallible

    success

    success value of original Fallible

    Return Value

    transformed Fallible

  • Applies transformation to Fallible and flattens nested Fallibles.

    Declaration

    Swift

    func flatMap<T>(_ transform: (_ success: Success) throws -> Fallible<T>) -> Fallible<T>

    Parameters

    transform

    block to apply. A fallible value returned from block will be a value (after flattening) of the transformed Fallible. An error thrown from block will be a failure value of the transformed Fallible. This block will not be executed if an original Fallible contains a failure. That failure will become a failure value of a transfomed Fallible

    success

    success value of original Fallible

    Return Value

    transformed Fallible

  • Applies transformation to Fallible

    Declaration

    Swift

    func tryRecover(_ transform: (_ failure: Swift.Error) throws -> Success) -> Fallible<Success>

    Parameters

    transform

    block to apply. A success value returned from block will be a success value of the transformed Fallible. An error thrown from block will be a failure value of a transformed Fallible. This block will not be executed if an original Fallible contains a success value. That success value will become a success value of a transfomed Fallible

    failure

    failure value of original Fallible

    Return Value

    transformed Fallible

  • Applies non-throwable transformation to Fallible

    Declaration

    Swift

    func recover(_ transform: (_ failure: Swift.Error) -> Success) -> Success

    Parameters

    transform

    block to apply. A success value returned from block will be returned from method. This block will not be executed if an original Fallible contains a success value. That success value will become a success value of a transfomed Fallible

    failure

    failure value of original Fallible

    Return Value

    success value

  • Applies non-throwable transformation to Fallible

    Declaration

    Swift

    func recover(with success: Success) -> Success

    Parameters

    success

    recover failure with

    Return Value

    success value

  • Flattens two nested Fallibles:

    < <Success> > => <Success>
    < <Failure> > => <Failure>
      <Failure>   => <Failure>
    

    Declaration

    Swift

    public func flatten() -> Fallible<Success.Success>

    Return Value

    flattened Fallible

  • Partial implementation of equality opeator for Fallibles You should check equalitu of unwrapped values rather then use this function

    Declaration

    Swift

    public static func == (lhs: Fallible, rhs: Fallible) -> Bool
  • Partial implementation of hashValue for Fallibles You should get hashValue ofunwrapped values rather then use this method

    Declaration

    Swift

    public var hashValue: Int { get }