Result

@_frozen
enum Result<Success, Failure> where Failure : Error
  • Provides a prism focused on the success side of a Result.

    Declaration

    Swift

    static var successPrism: Prism<Result<Success, Failure>, Success> { get }
  • Provides a prism focused on the failure side of a Result.

    Declaration

    Swift

    static var failurePrism: Prism<Result<Success, Failure>, Failure> { get }
  • Provides an Iso between Result and Either.

    Declaration

    Swift

    static var toEither: Iso<Result<Success, Failure>, Either<Failure, Success>> { get }
  • Provides an Iso between Result and Validated.

    Declaration

    Swift

    static var toValidated: Iso<Result<Success, Failure>, Validated<Failure, Success>> { get }
  • Converts this Result into an Either value.

    Declaration

    Swift

    func toEither() -> Either<Failure, Success>

    Return Value

    An Either.left if this is a Result.failure, or an Either.right if this is a Result.success

  • Converts this Result into a Try value.

    Declaration

    Swift

    func toTry() -> Try<Success>

    Return Value

    A Try.failure if this is a Result.failure, or a Try.success if this is a Result.success

  • Converts this Result into a Validated value.

    Declaration

    Swift

    func toValidated() -> Validated<Failure, Success>

    Return Value

    A Validated.invalid if this is a Result.failure, or a Validated.valid if this is a Result.success.

  • Converts this Result into a ValidatedNEA value.

    Declaration

    Swift

    func toValidatedNEA() -> ValidatedNEA<Failure, Success>

    Return Value

    A Validated.invalid with a NonEmptyArray of the Failure type if this is a Result.failure, or a Validated.valid if this is a Result.success.

  • Converts this Result into an Option value.

    Declaration

    Swift

    func toOption() -> Option<Success>

    Return Value

    Option.none if this is a Result.failure, or Option.some if this is a Result.success.

  • Applies the corresponding closure based on the value contained in this result.

    Declaration

    Swift

    func fold<B>(_ ifFailure: @escaping (Failure) -> B,
                 _ ifSuccess: @escaping (Success) -> B) -> B

    Parameters

    ifFailure

    Closure to be applied if this is a Result.failure.

    ifSuccess

    Closure to be applied if this is a Result.success.

    Return Value

    Output of the execution of the corresponding closure, based on the internal value of this Result.