Package com.github.tonivade.purefun.type
Interface Try<T>
- Type Parameters:
T- the wrapped value
- All Superinterfaces:
Applicable<Try<?>,,T> Bindable<Try<?>,,T> Kind<Try<?>,,T> Mappable<Try<?>,,T> TryOf<T>
- All Known Implementing Classes:
Try.Failure,Try.Success
public sealed interface Try<T>
extends TryOf<T>, Bindable<Try<?>,T>, Applicable<Try<?>,T>
permits Try.Success<T>, Try.Failure<T>
This type represents the success or failure of a computation. It has two possible values:
Try.success(): when the computation is successfulTry.failure(): when the result of a computation is an exception
You can obtain an Either<Throwable, T> from Try<T>
Note: it's serializable
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordstatic final recordNested classes/interfaces inherited from interface com.github.tonivade.purefun.core.Applicable
Applicable.Map2<F extends Applicable<F,?>, A, B>, Applicable.Map3<F extends Applicable<F, ?>, A, B, C>, Applicable.Map4<F extends Applicable<F, ?>, A, B, C, D>, Applicable.Map5<F extends Applicable<F, ?>, A, B, C, D, E> -
Method Summary
Modifier and TypeMethodDescriptiondefault <R> Try<R> static <T> Try<T> failure()static <T> Try<T> static <T> Try<T> default <R> Try<R> default <U> Ufold(Function1<? super Throwable, ? extends U> failureMapper, Function1<? super T, ? extends U> successMapper) static <R> Try<R> static <R> Try<R> fromEither(Either<? extends Throwable, ? extends R> value) getCause()default Tdefault Tdefault TgetOrElseThrow(Producer<? extends X> producer) static <T> Try<T> static <T> Try<T> illegalArgumentException(String cause) static <T> Try<T> static <T> Try<T> illegalStateException(String cause) booleanbooleandefault <R> Try<R> static <A,B, Z> Try <Z> static <T> Try<T> static <T> Try<T> noSuchElementException(String cause) static <T> Try<T> recoverWith(Class<X> type, Function1<? super X, ? extends T> mapper) sequence()stream()static <T> Try<T> success(T value) toEither()toOption()default <E> Validation<E, T> toValidation(Function1<? super Throwable, ? extends E> map) static <T> Try<T> static <T> Try<T> Methods inherited from interface com.github.tonivade.purefun.core.Applicable
zip, zipLeft, zipRight, zipWith
-
Method Details
-
success
-
failure
-
failure
-
failure
-
noSuchElementException
-
illegalArgumentException
-
illegalStateException
-
unsupportedOperationException
-
noSuchElementException
-
illegalArgumentException
-
illegalStateException
-
unsupportedOperationException
-
of
-
from
-
fromEither
-
map2
-
getOrElseThrow
T getOrElseThrow() -
getCause
Throwable getCause() -
isSuccess
boolean isSuccess() -
isFailure
boolean isFailure() -
map
-
ap
- Specified by:
apin interfaceApplicable<Try<?>,T>
-
mapError
-
flatMap
-
onFailure
-
onSuccess
-
recover
-
recoverWith
-
filter
-
filterNot
-
filterOrElse
-
fold
-
or
-
orElse
-
getOrElse
-
getOrElseNull
-
getOrElse
-
getOrElseThrow
- Throws:
X
-
stream
-
sequence
-
toOption
-
toEither
-
toValidation
-