-
-
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 <T extends Any, F extends Any> Result<T, F>fold(Function1<R, T> onSuccess, Function1<E, F> onFailure)Executes the appropriate lambda and returns a transformed result. 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>map(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. -
-
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
-
fold
final <T extends Any, F extends Any> Result<T, F> fold(Function1<R, T> onSuccess, Function1<E, F> onFailure)
Executes the appropriate lambda and returns a transformed result.
- Parameters:
onSuccess- Called with the success value, returns new success valueonFailure- Called with the failure value, returns new failure value
-
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
-
map
final <T extends Any> Result<T, E> map(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
-
-
-
-