Class Either<L,R>

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

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

    • ofLeft

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

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

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

      public R 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<L> leftConsumer, Consumer<R> rightConsumer)
      Applies the right consumer.
      Parameters:
      leftConsumer - The "Left" consumer
      rightConsumer - The "Right" consumer
    • match

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