Package 

Class CXResult


  • 
    public class CXResult<R extends Object>
    
                        

    A result type with a fixed CloudXError failure type. Used for operations that can either succeed with a value or fail with an error.

    • Method Detail

      • handle

         final Unit handle(Function1<R, Unit> onSuccess, Function1<CloudXError, Unit> onFailure)

        Handles the result with side-effect callbacks.

        Parameters:
        onSuccess - Called with the success value if this is a Success
        onFailure - Called with the error if this is a Failure
      • onSuccess

         final CXResult<R> onSuccess(Function1<R, Unit> action)

        Executes the lambda only if this is a Success.

        Parameters:
        action - Lambda to execute with the success value
      • onFailure

         final CXResult<R> onFailure(Function1<CloudXError, Unit> action)

        Executes the lambda only if this is a Failure.

        Parameters:
        action - Lambda to execute with the error
      • map

         final <T extends Any> CXResult<T> map(Function1<R, T> transform)

        Maps the success value to a new type, leaving failures unchanged.

        Parameters:
        transform - Function to transform the success value
      • flatMap

         final <T extends Any> CXResult<T> flatMap(Function1<R, CXResult<T>> transform)

        Flat maps the success value, allowing transformation to another CXResult.

        Parameters:
        transform - Function that transforms success value to a new CXResult
      • requireSuccess

         final R requireSuccess()

        Returns the success value or throws IllegalStateException if this is a Failure. Use when you know the result must be a Success.

      • requireFailure

         final CloudXError requireFailure()

        Returns the error or throws IllegalStateException if this is a Success. Use when you know the result must be a Failure.

      • successOrNull

         final R successOrNull()

        Returns the success value or null if this is a Failure.