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)
-
x
iff the value ofself
is.a(x)
for somex
;nil
otherwise.Declaration
Swift
public var a: A? { get }
-
x
iff the value ofself
is.b(x)
for somex
;nil
otherwise.Declaration
Swift
public var b: B? { get }
-
A textual representation of
self
.Declaration
Swift
public var description: String { get }
-
True iff
lhs
is equivalent torhs
.Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool
-
True iff
lhs
comes beforerhs
in 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
self
intohasher
.Declaration
Swift
public func hash(into hasher: inout Hasher)