Class Either<LEFT,​RIGHT>


  • public abstract class Either<LEFT,​RIGHT>
    extends Object
    A discriminated union of two parameters that holds a value of either the LEFT or RIGHT type.
    • Method Detail

      • isLeft

        public abstract boolean isLeft()
        Returns whether the instance holds a left value.
      • isRight

        public abstract boolean isRight()
        Returns whether the instance holds a right value.
      • getLeft

        public abstract LEFT getLeft()
        Returns the left value.
        Throws:
        IllegalStateException - if this instance does not hold a left value.
      • getRight

        public abstract RIGHT getRight()
        Returns the right value.
        Throws:
        IllegalStateException - if this instance does not hold a right value.
      • getLeftOption

        public abstract Optional<LEFT> getLeftOption()
        Left value or empty otherwise.
      • getRightOption

        public abstract Optional<RIGHT> getRightOption()
        Right value or empty otherwise.
      • transform

        public abstract <X> X transform​(java.util.function.Function<LEFT,​X> lhsTransformer,
                                        java.util.function.Function<RIGHT,​X> rhsTransformer)
        Apply a function based on whether the instance holds a left or right value.
      • ofLeft

        public static <LEFT,​RIGHT> Either<LEFT,​RIGHT> ofLeft​(LEFT value)
      • ofRight

        public static <LEFT,​RIGHT> Either<LEFT,​RIGHT> ofRight​(RIGHT value)