public final class TryCompanion extends Object
Try/Success/Failure.
import static javascalautils.TryCompanion.Failure;
import static javascalautils.TryCompanion.Success;
import static javascalautils.TryCompanion.Try;
Try<Integer> t = Try(() -> 9 / 3);
Try<String> ts = Success("Peter was here");
Try<String> tf = Failure(new Exception("Bad mojo!"));
| Modifier and Type | Method and Description |
|---|---|
static <T> Failure<T> |
Failure(Throwable throwable)
Creates an instance of
Failure wrapping the provided throwable. |
static <T> Success<T> |
Success(T value)
Creates an instance of
Success wrapping the provided value. |
static <T> Try<T> |
Try(ThrowableFunction0<T> function)
Creates an instance of
Try wrapping the result of the provided function. |
public static <T> Try<T> Try(ThrowableFunction0<T> function)
Try wrapping the result of the provided function. import static javascalautils.TryCompanion.Try; Try<Integer> t = Try(() -> 9 / 3);
T - The type for the Tryfunction - The function to render either the value T or raise an exception.Try.apply(ThrowableFunction0)public static <T> Failure<T> Failure(Throwable throwable)
Failure wrapping the provided throwable.
import static javascalautils.TryCompanion.Failure;
Try<String> tf = Failure(new Exception("Bad mojo!"));
T - The type for the Trythrowable - The throwable to wrapFailure.Failure(Throwable)public static <T> Success<T> Success(T value)
Success wrapping the provided value.
import static javascalautils.TryCompanion.Success;
Try<String> ts = Success("Peter was here");
T - The type for the Tryvalue - The value to wrapSuccess.Success(Object)Copyright © 2015, Peter Nerg Apache License v2.0