Interface Try<T>

All Superinterfaces:
Filter<Try,T,Try<T>>, HK<Try,T,Try<T>>
All Known Implementing Classes:
Try.Failure, Try.Success

public sealed interface Try<T> extends Filter<Try,T,Try<T>>, HK<Try,T,Try<T>> permits Try.Success<T>, Try.Failure<T>
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    Failure implementation
    static final record 
    Success implementation
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Try<T>
     
    default Try<T>
    filter(java.util.function.Predicate<? super T> predicate)
    Method called when the current data must be filtered using a given predicate.
    <B> Try<B>
    flatmap(java.util.function.Function<? super T,Try<B>> mapper)
     
    default <B> B
    fold(java.util.function.Function<? super T,B> success, java.util.function.Function<? super Throwable,B> failure)
     
    static <O> Try<O>
     
    default boolean
     
    default <B> Try<B>
    map(java.util.function.Function<? super T,? extends B> mapper)
     
    onFailure(java.util.function.Consumer<? super Throwable> onFailure)
     
    onSuccess(java.util.function.Consumer<? super T> onSuccess)
     
    default T
     
    <X extends Throwable>
    T
    orElseThrow(java.util.function.Function<? super Throwable,? extends X> exceptionSupplier)
     
    default <X extends Throwable>
    T
    orElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier)
     
    static <T> Try<T>
    pure(T value)
     
    recoverWith(java.util.function.Function<? super Throwable,T> t)
     
    default T
     
    default Try<T>
     
    static <T> Try<T>
    success(T value)
     
    default Promise<T>
     

    Methods inherited from interface org.smallibs.type.HK

    apply
  • Method Details

    • handle

      static <O> Try<O> handle(SupplierWithError<O> supplier)
    • toPromise

      default Promise<T> toPromise()
    • pure

      static <T> Try<T> pure(T value)
    • success

      static <T> Try<T> success(T value)
    • failure

      static <T> Try<T> failure(Throwable value)
    • filter

      default Try<T> filter(java.util.function.Predicate<? super T> predicate)
      Description copied from interface: Filter
      Method called when the current data must be filtered using a given predicate.
      Specified by:
      filter in interface Filter<Try,T,Try<T>>
      Parameters:
      predicate - The filter
      Returns:
      a filtered data
    • self

      default Try<T> self()
      Specified by:
      self in interface HK<Try,T,Try<T>>
    • map

      default <B> Try<B> map(java.util.function.Function<? super T,? extends B> mapper)
    • fold

      default <B> B fold(java.util.function.Function<? super T,B> success, java.util.function.Function<? super Throwable,B> failure)
    • recoverWith

      default T recoverWith(T t)
    • orElseThrow

      default <X extends Throwable> T orElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier) throws X
      Throws:
      X
    • orElseThrow

      default T orElseThrow() throws Throwable
      Throws:
      Throwable
    • isSuccess

      default boolean isSuccess()
    • recoverWith

      T recoverWith(java.util.function.Function<? super Throwable,T> t)
    • orElseThrow

      <X extends Throwable> T orElseThrow(java.util.function.Function<? super Throwable,? extends X> exceptionSupplier) throws X
      Throws:
      X
    • flatmap

      <B> Try<B> flatmap(java.util.function.Function<? super T,Try<B>> mapper)
    • onSuccess

      Try<T> onSuccess(java.util.function.Consumer<? super T> onSuccess)
    • onFailure

      Try<T> onFailure(java.util.function.Consumer<? super Throwable> onFailure)