-
-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Milestone
Description
Both the lift() and uncheck() methods would benefit from adding a signature that passes a custom exception handler, e.g:
default BiFunction<T1, T2, R> unchecked(Function<Exception, R> handler) {
return (arg1, arg2) -> {
try {
return apply(arg1, arg2);
} catch (final Exception e) {
return handler.apply(e);
}
};
}
default BiFunction<T1, T2, Optional<R>> lift(Function<Exception, Optional<R>> handler) {
return (arg1, arg2) -> {
try {
return Optional.of(apply(arg1, arg2));
} catch (Exception e) {
return handler.apply(e);
}
};
}(code not tested but I hope it conveys the idea)
The original signatures could just delegate to these appropriately.
I created similar classes/methods for a UI package (it was never good enough for a separate package like yours), and I found it very useful to be able to pass a handler, e.g. for displaying information to the user.
pivovarit and goostleek
Metadata
Metadata
Assignees
Labels
No labels