-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classResult.Successpublic final classResult.Failure
-
Method Summary
Modifier and Type Method Description final BooleangetIsSuccess()final BooleangetIsFailure()final Unitfold(Function1<R, Unit> onSuccess, Function1<E, Unit> onFailure)Executes the appropriate lambda based on the result type. final Result<R, E>onSuccess(Function1<R, Unit> action)Executes the lambda only if this is a Success. final Result<R, E>onFailure(Function1<E, Unit> action)Executes the lambda only if this is a Failure. final <T extends Any> Result<T, E>mapSuccess(Function1<R, T> transform)Maps the success value to a new type, leaving failures unchanged. final <F extends Any> Result<R, F>mapFailure(Function1<E, F> transform)Maps the failure value to a new type, leaving successes unchanged. final <T extends Any> Result<T, E>flatMap(Function1<R, Result<T, E>> transform)Flat maps the success value, allowing transformation to another Result. final RrequireSuccess()Returns the success value or throws IllegalStateException if this is a Failure. final ErequireFailure()Returns the failure value or throws IllegalStateException if this is a Success. final RsuccessOrNull()Returns the success value or null if this is a Failure. final EfailureOrNull()Returns the failure value or null if this is a Success. final <T extends Any> Result<T, E>asFailure()Converts a Failure to a different success type. -
-
Method Detail
-
getIsSuccess
final Boolean getIsSuccess()
-
getIsFailure
final Boolean getIsFailure()
-
fold
final Unit fold(Function1<R, Unit> onSuccess, Function1<E, Unit> onFailure)
Executes the appropriate lambda based on the result type.
- Parameters:
onSuccess- Called with the success value if this is a SuccessonFailure- Called with the failure value if this is a Failure
-
onSuccess
final Result<R, E> 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 Result<R, E> onFailure(Function1<E, Unit> action)
Executes the lambda only if this is a Failure.
- Parameters:
action- Lambda to execute with the failure value
-
mapSuccess
final <T extends Any> Result<T, E> mapSuccess(Function1<R, T> transform)
Maps the success value to a new type, leaving failures unchanged.
- Parameters:
transform- Function to transform the success value
-
mapFailure
final <F extends Any> Result<R, F> mapFailure(Function1<E, F> transform)
Maps the failure value to a new type, leaving successes unchanged.
- Parameters:
transform- Function to transform the failure value
-
flatMap
final <T extends Any> Result<T, E> flatMap(Function1<R, Result<T, E>> transform)
Flat maps the success value, allowing transformation to another Result.
- Parameters:
transform- Function that transforms success value to a new Result
-
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 E requireFailure()
Returns the failure value 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 E failureOrNull()
Returns the failure value or null if this is a Success.
-
-
-
-