@Test public void shouldRecoverFromResult() throws Throwable { CheckedFunction0<String> callable = () -> "Wrong Result"; CheckedFunction0<String> callableWithRecovery = CheckFunctionUtils.andThen(callable, (result, ex) -> { if(result.equals("Wrong Result")){ return "Bla"; } return result; }); String result = callableWithRecovery.apply(); assertThat(result).isEqualTo("Bla"); }
public static <T, R> CheckedFunction0<R> andThen(CheckedFunction0<T> function, CheckedFunction2<T, Throwable, R> handler) { return () -> { try { return handler.apply(function.apply(), null); } catch (Throwable throwable) { return handler.apply(null, throwable); } }; }
CheckFunctionUtils { public static <T, R> CheckedFunction0<R> andThen(CheckedFunction0<T> function, CheckedFunction2<T, Throwable, R> handler) { return () -> { try { return handler.apply(function.apply(), null); } catch (Throwable throwable) { return handler.apply(null, throwable); } }; } }
CheckFunctionUtils { public static <T, R> CheckedFunction0<R> andThen(CheckedFunction0<T> function, CheckedFunction2<T, Throwable, R> handler) { return () -> { try { return handler.apply(function.apply(), null); } catch (Throwable throwable) { return handler.apply(null, throwable); } }; } private  CheckFunctionUtils(); }
CheckFunctionUtils { public static <T, R> CheckedFunction0<R> andThen(CheckedFunction0<T> function, CheckedFunction2<T, Throwable, R> handler) { return () -> { try { return handler.apply(function.apply(), null); } catch (Throwable throwable) { return handler.apply(null, throwable); } }; } private  CheckFunctionUtils(); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        CheckedFunction1<Throwable, T> exceptionHandler); static CheckedFunction0<R> andThen(CheckedFunction0<T> function,
        CheckedFunction2<T, Throwable, R> handler); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        Predicate<T> resultPredicate, CheckedFunction1<T, T> resultHandler); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        List<Class<? extends Throwable>> exceptionTypes,
        CheckedFunction1<Throwable, T> exceptionHandler); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        Class<X> exceptionType,
        CheckedFunction1<Throwable, T> exceptionHandler); }
CheckFunctionUtils { public static <T, R> CheckedFunction0<R> andThen(CheckedFunction0<T> function, CheckedFunction2<T, Throwable, R> handler) { return () -> { try { return handler.apply(function.apply(), null); } catch (Throwable throwable) { return handler.apply(null, throwable); } }; } private  CheckFunctionUtils(); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        CheckedFunction1<Throwable, T> exceptionHandler); static CheckedFunction0<R> andThen(CheckedFunction0<T> function,
        CheckedFunction2<T, Throwable, R> handler); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        Predicate<T> resultPredicate, CheckedFunction1<T, T> resultHandler); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        List<Class<? extends Throwable>> exceptionTypes,
        CheckedFunction1<Throwable, T> exceptionHandler); static CheckedFunction0<T> recover(CheckedFunction0<T> function,
        Class<X> exceptionType,
        CheckedFunction1<Throwable, T> exceptionHandler);  }