Class Either.Left<L,R>

java.lang.Object
io.camunda.zeebe.util.Either.Left<L,R>
Type Parameters:
L - The left type
R - The right type
All Implemented Interfaces:
Either<L,R>
Enclosing interface:
Either<L,R>

public static final class Either.Left<L,R> extends Object implements Either<L,R>
A left for either a left or right. By convention, right is used for success and left for error.
  • Method Details

    • isRight

      public boolean isRight()
      Description copied from interface: Either
      Returns true if this Either is a Either.Right.
      Specified by:
      isRight in interface Either<L,R>
      Returns:
      true if right, false if left
    • isLeft

      public boolean isLeft()
      Description copied from interface: Either
      Returns true if this Either is a Either.Left.
      Specified by:
      isLeft in interface Either<L,R>
      Returns:
      true if left, false if right
    • get

      public R get()
      Description copied from interface: Either
      Returns the right value, if this is a Either.Right.
      Specified by:
      get in interface Either<L,R>
      Returns:
      the right value
    • getOrElse

      public R getOrElse(R defaultValue)
      Description copied from interface: Either
      Returns the right value, or a default value if this is a Either.Left.
      Specified by:
      getOrElse in interface Either<L,R>
      Parameters:
      defaultValue - the default value
      Returns:
      the right value, or the default value if this is a Either.Left
    • getLeft

      public L getLeft()
      Description copied from interface: Either
      Returns the left value, if this is a Either.Left.
      Specified by:
      getLeft in interface Either<L,R>
      Returns:
      the left value
    • map

      public <T> Either<L,T> map(Function<? super R,? extends T> right)
      Description copied from interface: Either
      Maps the right value, if this is a Either.Right.
      Specified by:
      map in interface Either<L,R>
      Type Parameters:
      T - the type of the resulting right value
      Parameters:
      right - the mapping function for the right value
      Returns:
      a mapped Either.Right or the same Either.Left
    • mapLeft

      public <T> Either<T,R> mapLeft(Function<? super L,? extends T> left)
      Description copied from interface: Either
      Maps the left value, if this is a Either.Left.
      Specified by:
      mapLeft in interface Either<L,R>
      Type Parameters:
      T - the type of the resulting left value
      Parameters:
      left - the mapping function for the left value
      Returns:
      a mapped Either.Left or the same Either.Right
    • flatMap

      public <T> Either<L,T> flatMap(Function<? super R,? extends Either<L,T>> right)
      Description copied from interface: Either
      Flatmaps the right value into a new Either, if this is a Either.Right.

      A common use case is to map a right value to a new right, unless some error occurs in which case the value can be mapped to a new left. Note that this flatMap does not allow to alter the type of the left side. Example:

      
       Either.<String, Integer>right(0) // => Right(0)
         .flatMap(x -> Either.right(x + 1)) // => Right(1)
         .flatMap(x -> Either.left("an error occurred")) // => Left("an error occurred")
         .getLeft(); // => "an error occurred"
       
      Specified by:
      flatMap in interface Either<L,R>
      Type Parameters:
      T - the type of the right side of the resulting either
      Parameters:
      right - the flatmapping function for the right value
      Returns:
      either a mapped Either.Right or a new Either.Left if this is a right; otherwise the same left, but cast to consider the new type of the right.
    • ifRight

      public void ifRight(Consumer<R> right)
      Description copied from interface: Either
      Performs the given action with the value if this is a Either.Right, otherwise does nothing.
      Specified by:
      ifRight in interface Either<L,R>
      Parameters:
      right - the consuming function for the right value
    • ifLeft

      public void ifLeft(Consumer<L> action)
      Description copied from interface: Either
      Performs the given action with the value if this is a Either.Left, otherwise does nothing.
      Specified by:
      ifLeft in interface Either<L,R>
      Parameters:
      action - the consuming function for the left value
    • ifRightOrLeft

      public void ifRightOrLeft(Consumer<R> rightAction, Consumer<L> leftAction)
      Description copied from interface: Either
      Performs the given right action with the value if this is a Either.Right, otherwise performs the given left action with the value.
      Specified by:
      ifRightOrLeft in interface Either<L,R>
      Parameters:
      rightAction - the consuming function for the right value
      leftAction - the consuming function for the left value
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object