Class TryExtensions
java.lang.Object
com.dudko.tools.safejavastreams.extensions.TryExtensions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Try<T>
from
(ThrowingSupplier<T> supplier) Wraps a ThrowingSupplier into Try.static <T> Try<T>
fromFuture
(CompletableFuture<T> future) Converts a CompletableFuture into Try synchronously.static <T> Try<T>
fromOptional
(Optional<T> optional, Supplier<? extends Throwable> ifEmpty) Converts an Optional to Try.
-
Constructor Details
-
TryExtensions
private TryExtensions()
-
-
Method Details
-
fromOptional
Converts an Optional to Try. Returns Failure if empty.- Type Parameters:
T
- type of the value- Parameters:
optional
- the optional valueifEmpty
- exception supplier if optional is empty- Returns:
- Try representing the result
-
from
Wraps a ThrowingSupplier into Try.- Type Parameters:
T
- result type- Parameters:
supplier
- the function that might throw- Returns:
- Try with result or exception
-
fromFuture
Converts a CompletableFuture into Try synchronously.- Type Parameters:
T
- type of result- Parameters:
future
- the future- Returns:
- Try with result or exception
-