Class Either<L,​R>

  • Type Parameters:
    L - left type
    R - right type
    All Implemented Interfaces:
    java.io.Serializable

    public final class Either<L,​R>
    extends java.lang.Object
    implements java.io.Serializable
    A data structure that can yield either a value of type L or a value of type R.
    See Also:
    Serialized Form
    • Method Detail

      • isLeft

        public boolean isLeft()
        Returns:
        true if it is a left Either
      • isRight

        public boolean isRight()
        Returns:
        true if it is a right Either
      • getLeft

        public L getLeft()
        Returns:
        the left value, or an IllegalStateException
        Throws:
        java.lang.IllegalStateException - if this is a right either
      • getRight

        public R getRight()
        Returns:
        the right value, or an IllegalStateException
        Throws:
        java.lang.IllegalStateException - if this is a left either
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • left

        public static <L,​R> Either<L,​R> left​(L value)
        Factory method for a left Either.
        Type Parameters:
        L - the left type
        R - the right type
        Parameters:
        value - the left of this Either
        Returns:
        a left Either with the provided value
      • right

        public static <L,​R> Either<L,​R> right​(R value)
        Factory method for a right Either.
        Type Parameters:
        L - the left type
        R - the right type
        Parameters:
        value - the right of this Either
        Returns:
        a right Either with the provided value