Either
public enum Either<A, B>
extension Either: CustomStringConvertible
extension Either: Equatable where A: Equatable, B: Equatable
extension Either: Comparable where A: Comparable, B: Comparable
extension Either: Hashable where A: Hashable, B: Hashable
An unbiased tagged union or sum type of exactly
two possible cases, .a and .b, having types A and B respectively.
When NOT to use Either: if there are asymmetrical semantics (e.g. A is special in some
manner), or when there are better names (i.e. meaning) that can be attached to the cases, a
domain-specific enum often results in more maintainable code and easier to use APIs.
When to use Either: good applications of Either come up in generic programming where there
are no defined semantics or information that can be gained from naming or biasing one of the two
cases.
-
Undocumented
Declaration
Swift
case a(A) -
Undocumented
Declaration
Swift
case b(B) -
xiff the value ofselfis.a(x)for somex;nilotherwise.Declaration
Swift
public var a: A? { get } -
xiff the value ofselfis.b(x)for somex;nilotherwise.Declaration
Swift
public var b: B? { get } -
A textual representation of
self.Declaration
Swift
public var description: String { get }
-
True iff
lhsis equivalent torhs.Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool
-
True iff
lhscomes beforerhsin an ordering where every.a(x)s is ordered before any.b(y),.a(x)s are ordered by increasingx, and.b(y)s are ordered by increasingy.Declaration
Swift
public static func < (lhs: `Self`, rhs: `Self`) -> Bool
-
Hashes
selfintohasher.Declaration
Swift
public func hash(into hasher: inout Hasher)
View on GitHub
Either Enumeration Reference