Class Either.Left<L,R>

java.lang.Object
com.dudko.tools.safejavastreams.core.Either<L,R>
com.dudko.tools.safejavastreams.core.Either.Left<L,R>
Enclosing class:
Either<L,R>

private static final class Either.Left<L,R> extends Either<L,R>
  • Field Details

    • value

      private final L value
  • Constructor Details

    • Left

      Left(L value)
  • Method Details

    • isRight

      public boolean isRight()
      Description copied from class: Either
      Checks whether the value is a Right.
      Specified by:
      isRight in class Either<L,R>
      Returns:
      true if this is a Right instance
    • isLeft

      public boolean isLeft()
      Description copied from class: Either
      Checks whether the value is a Left.
      Specified by:
      isLeft in class Either<L,R>
      Returns:
      true if this is a Left instance
    • getLeft

      public L getLeft()
      Description copied from class: Either
      Gets the Left value if present.
      Specified by:
      getLeft in class Either<L,R>
      Returns:
      Left value
    • getRight

      public R getRight()
      Description copied from class: Either
      Gets the Right value if present.
      Specified by:
      getRight in class Either<L,R>
      Returns:
      Right value
    • map

      public <T> Either<L,T> map(Function<? super R,? extends T> mapper)
      Description copied from class: Either
      Maps Right value to another type if present. If Left, the result remains Left.
      Specified by:
      map in class Either<L,R>
      Type Parameters:
      T - target type
      Parameters:
      mapper - function to map Right to T
      Returns:
      new Either
    • flatMap

      public <T> Either<L,T> flatMap(Function<? super R,Either<L,T>> mapper)
      Description copied from class: Either
      Applies a function that returns another Either to Right value. If Left, the result remains unchanged.
      Specified by:
      flatMap in class Either<L,R>
      Type Parameters:
      T - target type
      Parameters:
      mapper - function that returns Either
      Returns:
      new Either
    • ifRight

      public Either<L,R> ifRight(Consumer<? super R> action)
      Description copied from class: Either
      Executes action if this is Right.
      Specified by:
      ifRight in class Either<L,R>
      Parameters:
      action - consumer to run
      Returns:
      same Either
    • ifLeft

      public Either<L,R> ifLeft(Consumer<? super L> action)
      Description copied from class: Either
      Executes action if this is Left.
      Specified by:
      ifLeft in class Either<L,R>
      Parameters:
      action - consumer to run
      Returns:
      same Either
    • fold

      public <T> T fold(Function<? super L,? extends T> leftMapper, Function<? super R,? extends T> rightMapper)
      Description copied from class: Either
      Reduces this Either into a single value by applying one of the provided functions.
      Specified by:
      fold in class Either<L,R>
      Type Parameters:
      T - result type
      Parameters:
      leftMapper - function to apply to Left
      rightMapper - function to apply to Right
      Returns:
      reduced value
    • recover

      public Either<L,R> recover(Function<? super L,? extends R> recovery)
      Description copied from class: Either
      Converts Left into Right using a recovery function.
      Specified by:
      recover in class Either<L,R>
      Parameters:
      recovery - mapping function
      Returns:
      recovered Either
    • recoverWith

      public Either<L,R> recoverWith(Function<? super L,Either<L,R>> recovery)
      Description copied from class: Either
      Converts Left into another Either using a recovery function.
      Specified by:
      recoverWith in class Either<L,R>
      Parameters:
      recovery - function to convert Left into Either
      Returns:
      new Either
    • peek

      public Either<L,R> peek(Consumer<? super Either<L,R>> inspector)
      Description copied from class: Either
      Allows observing the value (for logging, debugging, etc.).
      Specified by:
      peek in class Either<L,R>
      Parameters:
      inspector - consumer that sees this Either
      Returns:
      same Either
    • toOptional

      public Optional<R> toOptional()
      Description copied from class: Either
      Converts Right value to Optional, or empty if Left.
      Specified by:
      toOptional in class Either<L,R>
      Returns:
      Optional with Right or empty
    • get

      public R get()
      Description copied from class: Either
      Converts this Either to a Stream.
      Specified by:
      get in class Either<L,R>
      Returns:
      Stream with this Either
    • toString

      public String toString()
      Overrides:
      toString in class Object