Package 

Class Result


  • 
    public class Result<R extends Object, E extends Object>
    
                        

    Helper class, purposed mainly as an explicit success/failure function result.

    • Method Summary

      Modifier and Type Method Description
      final Boolean getIsSuccess()
      final Boolean getIsFailure()
      final Unit fold(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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 Success
        onFailure - 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 value
        onFailure - 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
      • 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