Class NetworkResult

  • All Implemented Interfaces:
    java.io.Serializable

    
    public final class NetworkResult<T extends Object>
     implements Serializable
                        

    A discriminated union that encapsulates a successful outcome with a value of type T or a failure with an arbitrary Throwable exception.

    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Boolean isSuccess()
      final Boolean isFailure()
      final T getOrNull() Returns the encapsulated value if this instance represents success or null if it is failure.
      final Throwable exceptionOrNull() Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.
      String toString() Returns a string Success(v) if this instance represents success where v is a string representation of the value or a string Failure(x) if it is failure where x is a string representation of the exception.
      • Methods inherited from class java.lang.Object

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

    • Method Detail

      • getOrNull

         final T getOrNull()

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

        This function is a shorthand for getOrElse { null } (see getOrElse) or fold(onSuccess = { it }, onFailure = { null }) (see fold).

      • exceptionOrNull

         final Throwable exceptionOrNull()

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

        This function is a shorthand for fold(onSuccess = { null }, onFailure = { it }) (see fold).

      • toString

         String toString()

        Returns a string Success(v) if this instance represents success where v is a string representation of the value or a string Failure(x) if it is failure where x is a string representation of the exception.