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 Summary

      Modifier and Type Method Description
      final Boolean getIsSuccess()
      final Boolean getIsFailure()
      final Unit handle(Function1<R, Unit> onSuccess, Function1<CloudXError, Unit> onFailure) Handles the result with side-effect callbacks.
      final <T extends Any> T fold(Function1<R, T> onSuccess, Function1<CloudXError, T> onFailure) Transforms either branch into a single return type.
      final CXResult<R> onSuccess(Function1<R, Unit> action) Executes the lambda only if this is a Success.
      final CXResult<R> onFailure(Function1<CloudXError, Unit> action) Executes the lambda only if this is a Failure.
      final <T extends Any> CXResult<T> map(Function1<R, T> transform) Maps the success value to a new type, leaving failures unchanged.
      final <T extends Any> CXResult<T> flatMap(Function1<R, CXResult<T>> transform) Flat maps the success value, allowing transformation to another CXResult.
      final R requireSuccess() Returns the success value or throws IllegalStateException if this is a Failure.
      final CloudXError requireFailure() Returns the error or throws IllegalStateException if this is a Success.
      final R successOrNull() Returns the success value or null if this is a Failure.
      final CloudXError failureOrNull() Returns the error or null if this is a Success.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • fold

         final <T extends Any> T fold(Function1<R, T> onSuccess, Function1<CloudXError, T> onFailure)

        Transforms either branch into a single return type. Use when both success and failure should produce a value instead of a new CXResult.

      • 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.