Package com.github.skopylov58.functional
Interface TryUtils
public interface TryUtils
Collection of higher-order functions to handle exceptions in functional style.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Function that may throw an exception.static interface
Supplier that may throw an exception.static final record
Try Result for Java 14+static class
Try Result for Java 8+ -
Method Summary
Modifier and TypeMethodDescriptiondefault void
foo()
static Duration
default <T> TryUtils.Result<T>
onSuccessCatching
(TryUtils.Result<T> result, Try.CheckedConsumer<T> cons) static <E extends Throwable>
voidtoEither
(TryUtils.CheckedFunction<T, R> func) Higher-order function to convert partial functionT=>R
to total functionT=>Either<R, Exception>
static <T,
R> Function<T, CompletableFuture<R>> toFuture
(TryUtils.CheckedFunction<T, R> func) toOptional
(TryUtils.CheckedFunction<T, R> func) Higher-order function to convert partial functionT=>R
to total functionT=>Optional<R>
toOptional
(TryUtils.CheckedSupplier<T> supplier) Higher-order function to convert partial supplier()=>T
to total supplier()=>Optional<T>
static <T,
R> Function<T, TryUtils.Result<R>> toResult
(TryUtils.CheckedFunction<T, R> func) Higher-order function to convert partial functionT=>R
to total functionT=>Result<R>
static <T,
R> Function<T, TryUtils.ResultJava8<R>> toResultJava8
(TryUtils.CheckedFunction<T, R> func) static <T> Supplier<T>
toSupplier
(TryUtils.CheckedSupplier<T> supplier)
-
Method Details
-
toResult
Higher-order function to convert partial functionT=>R
to total functionT=>Result<R>
- Type Parameters:
T
- function input parameter typeR
- function result type- Parameters:
func
- partial functionT=>R
that may throw checked exception- Returns:
- total function
T=>Result<R>
-
onSuccessCatching
default <T> TryUtils.Result<T> onSuccessCatching(TryUtils.Result<T> result, Try.CheckedConsumer<T> cons) -
foo
default void foo() -
toOptional
Higher-order function to convert partial functionT=>R
to total functionT=>Optional<R>
- Type Parameters:
T
- function input parameter typeR
- function result type- Parameters:
func
- partial functionT=>R
that may throw checked exception- Returns:
- total function
T=>Optional<R>
-
toOptional
Higher-order function to convert partial supplier()=>T
to total supplier()=>Optional<T>
- Type Parameters:
T
- supplier result type- Parameters:
supplier
-()=>T
that may throw an exception- Returns:
- total supplier
()=>Optional<T>
-
toEither
Higher-order function to convert partial functionT=>R
to total functionT=>Either<R, Exception>
- Type Parameters:
T
- function input parameter typeR
- function result type- Parameters:
func
- partial functionT=>R
that may throw an exception- Returns:
- total function
T=>Either<R, Exception>
-
toResultJava8
-
toFuture
-
sneakyThrow
- Throws:
E extends Throwable
-
toSupplier
-
measure
-