Try

public class Try<A> : TryOf<A>

Describes the result of an operation that may have thrown errors or succeeded. The type parameter corresponds to the result type of the operation.

  • Creates a successful Try value.

    Declaration

    Swift

    public static func success(_ value: A) -> Try<A>

    Parameters

    value

    Value to be wrapped in a successful Try.

    Return Value

    A Try value wrapping the successful value.

  • Creates a failed Try value.

    Declaration

    Swift

    public static func failure(_ error: Error) -> Try<A>

    Parameters

    error

    An error.

    Return Value

    A Try value wrapping the error.

  • Creates a failed Try value.

    Declaration

    Swift

    public static func raise(_ error: Error) -> Try<A>

    Parameters

    error

    An error.

    Return Value

    A Try value wrapping the error.

  • Invokes a closure that may throw errors and wraps the result in a Try value.

    Declaration

    Swift

    public static func invoke(_ f: () throws -> A) -> Try<A>

    Parameters

    f

    Closure to be invoked.

    Return Value

    A Try value wrapping the result of the invocation or any error that it may have thrown.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: TryOf<A>) -> Try<A>

    Parameters

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to Try.

  • Applies the provided closures based on the content of this Try value.

    Declaration

    Swift

    public func fold<B>(_ fe: (Error) -> B, _ fa: (A) throws -> B) -> B

    Parameters

    fe

    Closure to apply if the contained value in this Try is an error.

    fa

    Closure to apply if the contained value in this Try is a successful value.

    Return Value

    Result of applying the corresponding closure to this value.

  • Obtains the wrapped error in this Try.

    Declaration

    Swift

    public func failed() -> Try<Error>

    Return Value

    A successful error or a failure with TryError.unsupportedOperation if this value was not an error.

  • Obtains the value wrapped in this Try or a default value if it contains an error.

    Declaration

    Swift

    public func getOrElse(_ defaultValue: A) -> A

    Parameters

    defaultValue

    Default value for the failure case.

    Return Value

    Value wrapped in this Try, or the default value if it was an error.

  • Attempts to recover if the contained value in this Try is an error.

    Declaration

    Swift

    public func recoverWith(_ f: (Error) -> Try<A>) -> Try<A>

    Parameters

    f

    Recovery function.

    Return Value

    A Try value from the recovery, or the original value if it was not an error.

  • Recovers if the contained value in this Try is an error.

    Declaration

    Swift

    public func recover(_ f: @escaping (Error) -> A) -> Try<A>

    Parameters

    f

    Recovery function.

    Return Value

    A Try value from the recovery, or the original value if it was not an error.

  • Undocumented

    Declaration

    Swift

    public static func pSuccessPrism<B>() -> PPrism<Try<A>, Try<B>, A, B>
  • Undocumented

    Declaration

    Swift

    public static func successPrism() -> Prism<Try<A>, A>
  • Undocumented

    Declaration

    Swift

    public static func failurePrism() -> Prism<Try<A>, Error>
  • Undocumented

    Declaration

    Swift

    public static func toPEither<B>() -> PIso<Try<A>, Try<B>, Either<Error, A>, Either<Error, B>>
  • Undocumented

    Declaration

    Swift

    public static func toEither() -> Iso<Try<A>, Either<Error, A>>
  • Undocumented

    Declaration

    Swift

    public static func toPValidated<B>() -> PIso<Try<A>, Try<B>, Validated<Error, A>, Validated<Error, B>>
  • Undocumented

    Declaration

    Swift

    public static func toValidated() -> Iso<Try<A>, Validated<Error, A>>
  • Declaration

    Swift

    public var description: String { get }