Other Enumerations

The following enumerations are available globally.

  • 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.

    See more

    Declaration

    Swift

    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