Class TryExtensions

java.lang.Object
com.dudko.tools.safejavastreams.extensions.TryExtensions

public final class TryExtensions extends Object
  • Constructor Details

    • TryExtensions

      private TryExtensions()
  • Method Details

    • fromOptional

      public static <T> Try<T> fromOptional(Optional<T> optional, Supplier<? extends Throwable> ifEmpty)
      Converts an Optional to Try. Returns Failure if empty.
      Type Parameters:
      T - type of the value
      Parameters:
      optional - the optional value
      ifEmpty - exception supplier if optional is empty
      Returns:
      Try representing the result
    • from

      public static <T> Try<T> from(ThrowingSupplier<T> supplier)
      Wraps a ThrowingSupplier into Try.
      Type Parameters:
      T - result type
      Parameters:
      supplier - the function that might throw
      Returns:
      Try with result or exception
    • fromFuture

      public static <T> Try<T> fromFuture(CompletableFuture<T> future)
      Converts a CompletableFuture into Try synchronously.
      Type Parameters:
      T - type of result
      Parameters:
      future - the future
      Returns:
      Try with result or exception