Class Try.Success<T>

java.lang.Object
com.dudko.tools.safejavastreams.core.Try<T>
com.dudko.tools.safejavastreams.core.Try.Success<T>
Type Parameters:
T - type of the value
Enclosing class:
Try<T>

public static final class Try.Success<T> extends Try<T>
Represents a successful computation.
  • Field Details

    • value

      private final T value
  • Constructor Details

    • Success

      public Success(T value)
  • Method Details

    • isSuccess

      public boolean isSuccess()
      Description copied from class: Try
      Returns true if this is a Success.
      Specified by:
      isSuccess in class Try<T>
    • get

      public T get()
      Description copied from class: Try
      Returns the value if this is a Success, otherwise throws the exception.
      Specified by:
      get in class Try<T>
    • map

      public <U> Try<U> map(Function<? super T,? extends U> mapper)
      Description copied from class: Try
      Applies a function to the value if Success, otherwise propagates the Failure.
      Specified by:
      map in class Try<T>
      Type Parameters:
      U - mapped value type
      Parameters:
      mapper - function to apply
      Returns:
      new Try with mapped value or the original Failure
    • flatMap

      public <U> Try<U> flatMap(Function<? super T,Try<U>> mapper)
      Description copied from class: Try
      Applies a function that returns Try if Success, otherwise propagates the Failure.
      Specified by:
      flatMap in class Try<T>
      Type Parameters:
      U - mapped value type
      Parameters:
      mapper - function to apply
      Returns:
      result of function or the original Failure
    • recover

      public Try<T> recover(Function<? super Throwable,? extends T> recovery)
      Description copied from class: Try
      Applies a recovery function if this is a Failure.
      Specified by:
      recover in class Try<T>
      Parameters:
      recovery - recovery function
      Returns:
      Success with recovered value or original Success
    • recoverWith

      public Try<T> recoverWith(Function<? super Throwable,Try<T>> recovery)
      Description copied from class: Try
      Applies a recovery function that returns Try if this is a Failure.
      Specified by:
      recoverWith in class Try<T>
      Parameters:
      recovery - recovery function
      Returns:
      Try from recovery or original Success
    • fold

      public <U> U fold(Function<? super Throwable,? extends U> failureMapper, Function<? super T,? extends U> successMapper)
      Description copied from class: Try
      Applies one of two functions depending on whether it's a Success or Failure.
      Specified by:
      fold in class Try<T>
      Type Parameters:
      U - return type
      Parameters:
      failureMapper - mapper for Failure
      successMapper - mapper for Success
      Returns:
      result of applying the corresponding function
    • peek

      public Try<T> peek(Consumer<? super T> action)
      Description copied from class: Try
      Performs side-effecting operation on Success.
      Specified by:
      peek in class Try<T>
      Parameters:
      action - consumer to run if Success
      Returns:
      the same Try instance
    • peekFailure

      public Try<T> peekFailure(Consumer<? super Throwable> action)
      Description copied from class: Try
      Performs side-effecting operation on Failure.
      Specified by:
      peekFailure in class Try<T>
      Parameters:
      action - consumer to run if Failure
      Returns:
      the same Try instance
    • toOptional

      public Optional<T> toOptional()
      Description copied from class: Try
      Returns the value as Optional if Success, otherwise empty.
      Specified by:
      toOptional in class Try<T>
    • getError

      public Throwable getError()
      Specified by:
      getError in class Try<T>
    • toEither

      public <L> Either<L,T> toEither(Function<? super Throwable,? extends L> mapper)
      Specified by:
      toEither in class Try<T>