Either

@available(swift, deprecated: 100000)
public protocol Either

A type that can exclusively represent one of two values.

By design, an either is symmetrical and treats its variants the same. For representing the most common case of success and failures, prefer a result type like TaskResult.

This protocol describes a minimal interface for representing a result type to overcome limitations with Swift. It is expected that it will be removed completely at some later point.

  • One of the two possible results.

    By convention, the left side indicates failure, typically through a Swift Error.

    A typealias instead of an associatedtype to avoid breaking compatibility when what we actually want becomes representable. See also https://github.com/apple/swift/blob/master/docs/LibraryEvolution.rst#protocols.

    Declaration

    Swift

    typealias Left = Error
  • One of the two possible results.

    By convention, the right side is used to hold a correct value.

    Declaration

    Swift

    associatedtype Right
  • Creates a left-biased instance.

    Declaration

    Swift

    init(left: Left)
  • Creates a right-biased instance.

    Declaration

    Swift

    init(right: Right)
  • Creates an instance by evaluating a throwing body, capturing its returned value as a right bias, or the thrown error as a left bias.

    Declaration

    Swift

    init(catching body: () throws -> Right)
  • Returns the right-biased value as a throwing expression.

    Use this method to retrieve the value of this instance if it is right-biased or to throw the error if it is left-biased.

    Declaration

    Swift

    func get() throws -> Right