Interface ServiceResult<SuccessType>

  • Type Parameters:
    SuccessType - the return type for a successful operation.
    All Superinterfaces:
    Result<SuccessType,​java.lang.String>
    All Known Implementing Classes:
    Failure, Success

    public interface ServiceResult<SuccessType>
    extends Result<SuccessType,​java.lang.String>
    The ServiceResult type is an attempt at the function construct of Either. In this implementation a ServiceResult can define either success or failure (error) using the same type.
    Since:
    1.14.0
    • Method Detail

      • map

        <T> T map​(java.util.function.Function<SuccessType,​T> successFunction,
                  java.util.function.Function<java.lang.String,​T> errorFunction)
        Description copied from interface: Result
        A mapping function that maps to either SuccessType or FailureType depending on success or failure of the operation.
        Specified by:
        map in interface Result<SuccessType,​java.lang.String>
        Type Parameters:
        T - the resultant type
        Parameters:
        successFunction - the mapping function to map the SuccessType to the resultant type
        errorFunction - the mapping function to map the FailureType to the resultant error type
        Returns:
        result of type T
      • getMessage

        SuccessType getMessage()
        Description copied from interface: Result
        The return message of a successful operation. The return type is of type SuccessType
        Specified by:
        getMessage in interface Result<SuccessType,​java.lang.String>
        Returns:
        the result of the operation
      • getErrorMessage

        java.lang.String getErrorMessage()
        Description copied from interface: Result
        The return message of a failed operation. The return type is of type FailureType
        Specified by:
        getErrorMessage in interface Result<SuccessType,​java.lang.String>
        Returns:
        the failure message of why the operation did not succeed.
      • ifFailure

        default ServiceResult<SuccessType> ifFailure​(java.util.function.Consumer<? super java.lang.String> consumer)
        If the result of the operation has failed, invoke the specified consumer with the value, otherwise do nothing.
        Parameters:
        consumer - block to be executed if a value is present
        Returns:
        this ServiceResult
        Throws:
        java.lang.NullPointerException - if value is present and consumer is null