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
Represents a successful 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> U
fold
(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()
boolean
Returns 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
-
value
-
-
Constructor Details
-
Success
-
-
Method Details
-
isSuccess
public boolean isSuccess()Description copied from class:Try
Returns true if this is a Success. -
get
Description copied from class:Try
Returns the value if this is a Success, otherwise throws the exception. -
map
Description copied from class:Try
Applies a function to the value if Success, otherwise propagates the Failure. -
flatMap
Description copied from class:Try
Applies a function that returns Try if Success, otherwise propagates the Failure. -
recover
Description copied from class:Try
Applies a recovery function if this is a Failure. -
recoverWith
Description copied from class:Try
Applies a recovery function that returns Try if this is a Failure.- Specified by:
recoverWith
in 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:Try
Applies one of two functions depending on whether it's a Success or Failure. -
peek
Description copied from class:Try
Performs side-effecting operation on Success. -
peekFailure
Description copied from class:Try
Performs side-effecting operation on Failure.- Specified by:
peekFailure
in classTry<T>
- Parameters:
action
- consumer to run if Failure- Returns:
- the same Try instance
-
toOptional
Description copied from class:Try
Returns the value as Optional if Success, otherwise empty.- Specified by:
toOptional
in classTry<T>
-
getError
-
toEither
-