-
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classCXResult.Successpublic final classCXResult.Failure
-
Method Summary
Modifier and Type Method Description final BooleangetIsSuccess()final BooleangetIsFailure()final Unithandle(Function1<R, Unit> onSuccess, Function1<CloudXError, Unit> onFailure)Handles the result with side-effect callbacks. 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 RrequireSuccess()Returns the success value or throws IllegalStateException if this is a Failure. final CloudXErrorrequireFailure()Returns the error or throws IllegalStateException if this is a Success. final RsuccessOrNull()Returns the success value or null if this is a Failure. final CloudXErrorfailureOrNull()Returns the error or null if this is a Success. -
-
Method Detail
-
getIsSuccess
final Boolean getIsSuccess()
-
getIsFailure
final Boolean getIsFailure()
-
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 SuccessonFailure- 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.
-
failureOrNull
final CloudXError failureOrNull()
Returns the error or null if this is a Success.
-
-
-
-