From 2eb9699e7975431d7421829628fc560034538653 Mon Sep 17 00:00:00 2001 From: Konstantin Sobolev Date: Mon, 6 Nov 2017 13:14:40 -0800 Subject: [PATCH] asm: replaced `from(f,ef)` with more composable `catching` --- .../main/java/ws/epigraph/assembly/Asm.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/java/core/src/main/java/ws/epigraph/assembly/Asm.java b/java/core/src/main/java/ws/epigraph/assembly/Asm.java index 7075cbea7..38e1daeb2 100644 --- a/java/core/src/main/java/ws/epigraph/assembly/Asm.java +++ b/java/core/src/main/java/ws/epigraph/assembly/Asm.java @@ -56,25 +56,14 @@ public interface Asm { return (dto, projection, ctx) -> assemble(f.apply(dto), projection, ctx); } - /** - * Composes a function {@code f} with an assembler by applying {@code f} to the data object - * before {@code assemble} call. Ideologically it would be similar to {@code f.andThen(this)} - * - * @param f function to run on the data object - * @param ef function to be called if {@code f} application produces an error - * @param new data object type - * - * @return composed assembler - */ - default @NotNull Asm from(@NotNull Function f, @NotNull Function ef) { + // parameterize on exception class? + default @NotNull Asm catching(@NotNull Function handler) { return (dto, projection, ctx) -> { - D d; try { - d = f.apply(dto); - } catch (Exception ex) { - return ef.apply(ex); + return assemble(dto, projection, ctx); + } catch (Exception e) { + return handler.apply(e); } - return assemble(d, projection, ctx); }; }