Class Either<L,​R>

  • Type Parameters:
    L - the type of Left
    R - the type of Right
    Direct Known Subclasses:
    Either.Left, Either.Right

    @Public
    @TypeInfo(EitherTypeInfoFactory.class)
    public abstract class Either<L,​R>
    extends Object
    This type represents a value of one two possible types, Left or Right (a disjoint union), inspired by Scala's Either type.
    • Constructor Detail

      • Either

        public Either()
    • Method Detail

      • Left

        public static <L,​R> Either<L,​R> Left​(L value)
        Create a Left value of Either
      • Right

        public static <L,​R> Either<L,​R> Right​(R value)
        Create a Right value of Either
      • isLeft

        public final boolean isLeft()
        Returns:
        true if this is a Left value, false if this is a Right value
      • isRight

        public final boolean isRight()
        Returns:
        true if this is a Right value, false if this is a Left value
      • obtainLeft

        @Internal
        public static <L,​R> Either.Left<L,​R> obtainLeft​(Either<L,​R> input,
                                                                    TypeSerializer<L> leftSerializer)
        Utility function for EitherSerializer to support object reuse.

        To support object reuse both subclasses of Either contain a reference to an instance of the other type. This method provides access to and initializes the cross-reference.

        Type Parameters:
        L - the type of Left
        R - the type of Right
        Parameters:
        input - container for Left or Right value
        leftSerializer - for creating an instance of the left type
        Returns:
        input if Left type else input's Left reference
      • obtainRight

        @Internal
        public static <L,​R> Either.Right<L,​R> obtainRight​(Either<L,​R> input,
                                                                      TypeSerializer<R> rightSerializer)
        Utility function for EitherSerializer to support object reuse.

        To support object reuse both subclasses of Either contain a reference to an instance of the other type. This method provides access to and initializes the cross-reference.

        Type Parameters:
        L - the type of Left
        R - the type of Right
        Parameters:
        input - container for Left or Right value
        rightSerializer - for creating an instance of the right type
        Returns:
        input if Right type else input's Right reference