Either

public class Either<A, B> : EitherOf<A, B>

Sum type of types A and B. Represents a value of either one of those types, but not both at the same time. Values of type A are called left; values of type B are called right.

  • Constructs a left value given an instance of A.

    Declaration

    Swift

    public static func left(_ a: A) -> Either<A, B>
  • Constructs a right value given an instance of B.

    Declaration

    Swift

    public static func right(_ b: B) -> Either<A, B>
  • Safe downcast to Either<A, B>.

    Declaration

    Swift

    public static func fix(_ fa: EitherOf<A, B>) -> Either<A, B>
  • Applies the provided closures based on the content of this Either value.

    Declaration

    Swift

    public func fold<C>(_ fa: (A) -> C, _ fb: (B) -> C) -> C

    Parameters

    fa

    Closure to apply if the contained value in this Either is of type A.

    fb

    Closure to apply if the contained value in this Either is of type B.

    Return Value

    Result of applying the corresponding closure to this value.

  • Checks if this value belongs to the left type.

    Declaration

    Swift

    public var isLeft: Bool { get }
  • Checks if this value belongs to the right type.

    Declaration

    Swift

    public var isRight: Bool { get }
  • Attempts to obtain a value of the left type.

    This propery is unsafe and can cause fatal errors if it is invoked on a right value.

    Declaration

    Swift

    public var leftValue: A { get }
  • Attempts to obtain a value of the right type.

    This property is unsafe and can cause fatal errors if it is invoked on a left value.

    Declaration

    Swift

    public var rightValue: B { get }
  • Reverses the types of this either. Left values become right values and vice versa.

    Declaration

    Swift

    public func swap() -> Either<B, A>
  • Transforms both type parameters, preserving its structure.

    Declaration

    Swift

    public func bimap<C, D>(_ fa: (A) -> C, _ fb: (B) -> D) -> Either<C, D>

    Parameters

    fa

    Closure to be applied when there is a left value.

    fb

    Closure to be applied when there is a right value.

  • Converts this Either to an Option.

    This conversion is lossy. Left values are mapped to Option.none() and right values to Option.some(). The original `Either cannot be reconstructed from the output of this conversion.

    Declaration

    Swift

    public func toOption() -> Option<B>
  • Obtains the value wrapped if it is a right value, or the default value provided as an argument.

    Declaration

    Swift

    public func getOrElse(_ defaultValue: B) -> B
  • Filters the right values, providing a default left value if the do not match the provided predicate.

    Declaration

    Swift

    public func filterOrElse(_ predicate : @escaping (B) -> Bool, _ defaultValue : A) -> Either<A, B>
  • Undocumented

    Declaration

    Swift

    public static func traversal() -> Traversal<Either<A, B>, B>
  • Undocumented

    Declaration

    Swift

    public static func each() -> EachInstance<A, B>
  • Undocumented

    See more

    Declaration

    Swift

    public class EachInstance<L, R> : Each
  • Undocumented

    Declaration

    Swift

    public func toResult() -> Result<B, A>
  • Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public var debugDescription: String { get }