Interface TryUtils


public interface TryUtils
Collection of higher-order functions to handle exceptions in functional style.
  • Method Details

    • toResult

      static <T, R> Function<T,TryUtils.Result<R>> toResult(TryUtils.CheckedFunction<T,R> func)
      Higher-order function to convert partial function T=>R to total function T=>Result<R>
      Type Parameters:
      T - function input parameter type
      R - function result type
      Parameters:
      func - partial function T=>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

      static <T, R> Function<T,Optional<R>> toOptional(TryUtils.CheckedFunction<T,R> func)
      Higher-order function to convert partial function T=>R to total function T=>Optional<R>
      Type Parameters:
      T - function input parameter type
      R - function result type
      Parameters:
      func - partial function T=>R that may throw checked exception
      Returns:
      total function T=>Optional<R>
    • toOptional

      static <T> Supplier<Optional<T>> toOptional(TryUtils.CheckedSupplier<T> supplier)
      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

      static <T, R> Function<T,Either<Exception,R>> toEither(TryUtils.CheckedFunction<T,R> func)
      Higher-order function to convert partial function T=>R to total function T=>Either<R, Exception>
      Type Parameters:
      T - function input parameter type
      R - function result type
      Parameters:
      func - partial function T=>R that may throw an exception
      Returns:
      total function T=>Either<R, Exception>
    • toResultJava8

      static <T, R> Function<T,TryUtils.ResultJava8<R>> toResultJava8(TryUtils.CheckedFunction<T,R> func)
    • toFuture

      static <T, R> Function<T,CompletableFuture<R>> toFuture(TryUtils.CheckedFunction<T,R> func)
    • sneakyThrow

      static <E extends Throwable> void sneakyThrow(Throwable e) throws E
      Throws:
      E extends Throwable
    • toSupplier

      static <T> Supplier<T> toSupplier(TryUtils.CheckedSupplier<T> supplier)
    • measure

      static Duration measure(Runnable runnable)