Package 

Class Try


  • 
    public class Try<Success extends Object, Failure extends Object>
    
                        

    A Result type which can be used as a return type.

    • Method Summary

      Modifier and Type Method Description
      abstract Boolean getIsSuccess()
      abstract Boolean getIsFailure()
      abstract Success getOrNull() Returns the encapsulated value if this instance represents success or null if it is failure.
      abstract Failure failureOrNull() Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.
      final <R extends Any> Try<R, Failure> map(Function1<Success, R> transform) Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure.
      final <F extends Any> Try<Success, F> mapFailure(Function1<Failure, F> transform) Returns the encapsulated result of the given transform function applied to the encapsulated failure if this instance represents failure or the original encapsulated success value if it is a success.
      final <R extends Any> R fold(Function1<Success, R> onSuccess, Function1<Failure, R> onFailure) Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated value if it is failure.
      final Try<Success, Failure> onSuccess(Function1<Success, Unit> action) Performs the given action on the encapsulated value if this instance represents success.
      final Try<Success, Failure> onFailure(Function1<Failure, Unit> action) Performs the given action on the encapsulated value if this instance represents failure.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getOrNull

         abstract Success getOrNull()

        Returns the encapsulated value if this instance represents success or null if it is failure.

      • failureOrNull

         abstract Failure failureOrNull()

        Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.

      • map

         final <R extends Any> Try<R, Failure> map(Function1<Success, R> transform)

        Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure.

      • mapFailure

         final <F extends Any> Try<Success, F> mapFailure(Function1<Failure, F> transform)

        Returns the encapsulated result of the given transform function applied to the encapsulated failure if this instance represents failure or the original encapsulated success value if it is a success.

      • fold

         final <R extends Any> R fold(Function1<Success, R> onSuccess, Function1<Failure, R> onFailure)

        Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated value if it is failure.

      • onSuccess

         final Try<Success, Failure> onSuccess(Function1<Success, Unit> action)

        Performs the given action on the encapsulated value if this instance represents success. Returns the original Try unchanged.

      • onFailure

         final Try<Success, Failure> onFailure(Function1<Failure, Unit> action)

        Performs the given action on the encapsulated value if this instance represents failure. Returns the original Try unchanged.