Either

public enum Either<Left, Right>
extension Either: Equatable where Left: Equatable, Right: Equatable

Either is a sum type which holds either of two generic values.

Example Usage

let one = Either<String,Int>.left("one")
let two = Either<String,Int>.right(2)

Cases

  • The left value.

    Declaration

    Swift

    case left(Left)
  • The right value.

    Declaration

    Swift

    case right(Right)

Instance Properties

  • let one = Either<String,Int>.left("one")
    one.left // => .some("one")
    one.right // => nil
    

    Declaration

    Swift

    public var left: Left? { get }

    Return Value

    The left value, if it is exists. Otherwise, nil.

  • let one = Either<String,Int>.right(1)
    one.left // => nil
    one.right // => .some(1)
    

    Declaration

    Swift

    public var right: Right? { get }

    Return Value

    The right value, if it is exists. Otherwise, nil.