Class Either<LEFT_TYPE,RIGHT_TYPE>

java.lang.Object
dev.voidframework.core.lang.Either<LEFT_TYPE,RIGHT_TYPE>
Type Parameters:
LEFT_TYPE - Type of "Left" value
RIGHT_TYPE - Type of "Right" value

public class Either<LEFT_TYPE,RIGHT_TYPE> extends Object
Represents a value of one or two possible types (a disjoint union).
  • Method Details

    • ofLeft

      public static <LEFT_TYPE, RIGHT_TYPE> Either<LEFT_TYPE,RIGHT_TYPE> ofLeft(LEFT_TYPE left)
      Creates a Either with left value set.
      Type Parameters:
      LEFT_TYPE - Type of "Left" value
      RIGHT_TYPE - Type of "Right" value
      Parameters:
      left - The "Left" value
      Returns:
      The newly created Either
    • ofRight

      public static <LEFT_TYPE, RIGHT_TYPE> Either<LEFT_TYPE,RIGHT_TYPE> ofRight(RIGHT_TYPE right)
      Creates a Either with right value set.
      Type Parameters:
      LEFT_TYPE - Type of "Left" value
      RIGHT_TYPE - Type of "Right" value
      Parameters:
      right - The "Right" value
      Returns:
      The newly created Either
    • getLeft

      public LEFT_TYPE getLeft()
      Returns the "Left" value.
      Returns:
      The "Left" value
    • getRight

      public RIGHT_TYPE getRight()
      Returns the "Right" value.
      Returns:
      The "Right" value
    • hasLeft

      public boolean hasLeft()
      Checks if the "Left" value is set.
      Returns:
      true if the "Left" value is set, otherwise, false
    • hasRight

      public boolean hasRight()
      Checks if the "Right" value is set.
      Returns:
      true if the "Right" value is set, otherwise, false
    • match

      public void match(Consumer<LEFT_TYPE> leftConsumer, Consumer<RIGHT_TYPE> rightConsumer)
      Applies the right consumer.
      Parameters:
      leftConsumer - The "Left" consumer
      rightConsumer - The "Right" consumer
    • match

      public <RETURN_TYPE> RETURN_TYPE match(Function<LEFT_TYPE,RETURN_TYPE> leftFunction, Function<RIGHT_TYPE,RETURN_TYPE> rightFunction)
      Applies the right function.
      Type Parameters:
      RETURN_TYPE - The returned value type
      Parameters:
      leftFunction - The "Left" function
      rightFunction - The "Right" function
      Returns:
      The result of the applied function