Class Try.Failure<T>
java.lang.Object
com.dudko.tools.safejavastreams.core.Try<T>
com.dudko.tools.safejavastreams.core.Try.Failure<T>
- Type Parameters:
T- type of the value
Represents a failed computation.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.dudko.tools.safejavastreams.core.Try
Try.Failure<T>, Try.Success<T> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<U> Try<U>Applies a function that returns Try if Success, otherwise propagates the Failure.<U> Ufold(Function<? super Throwable, ? extends U> failureMapper, Function<? super T, ? extends U> successMapper) Applies one of two functions depending on whether it's a Success or Failure.get()Returns the value if this is a Success, otherwise throws the exception.getError()booleanReturns true if this is a Success.<U> Try<U>Applies a function to the value if Success, otherwise propagates the Failure.Performs side-effecting operation on Success.peekFailure(Consumer<? super Throwable> action) Performs side-effecting operation on Failure.Applies a recovery function if this is a Failure.recoverWith(Function<? super Throwable, Try<T>> recovery) Applies a recovery function that returns Try if this is a Failure.Returns the value as Optional if Success, otherwise empty.Methods inherited from class com.dudko.tools.safejavastreams.core.Try
failure, filter, getOrElse, getOrElseGet, getOrThrow, getOrThrow, isFailure, isFailureOf, of, onFailure, onSuccess, success, toStream
-
Field Details
-
exception
-
-
Constructor Details
-
Failure
-
-
Method Details
-
isSuccess
public boolean isSuccess()Description copied from class:TryReturns true if this is a Success. -
get
Description copied from class:TryReturns the value if this is a Success, otherwise throws the exception. -
map
Description copied from class:TryApplies a function to the value if Success, otherwise propagates the Failure. -
flatMap
Description copied from class:TryApplies a function that returns Try if Success, otherwise propagates the Failure. -
recover
Description copied from class:TryApplies a recovery function if this is a Failure. -
recoverWith
Description copied from class:TryApplies a recovery function that returns Try if this is a Failure.- Specified by:
recoverWithin classTry<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:TryApplies one of two functions depending on whether it's a Success or Failure. -
peek
Description copied from class:TryPerforms side-effecting operation on Success. -
peekFailure
Description copied from class:TryPerforms side-effecting operation on Failure.- Specified by:
peekFailurein classTry<T>- Parameters:
action- consumer to run if Failure- Returns:
- the same Try instance
-
toOptional
Description copied from class:TryReturns the value as Optional if Success, otherwise empty.- Specified by:
toOptionalin classTry<T>
-
getError
-
toEither
-