Skip to content

Commit b4478fe

Browse files
committed
✨ throwableFunction compose|andThen methods
1 parent b83dc9d commit b4478fe

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

summer-java-core/src/main/java/com/dianpoint/summer/lang/ThrowableFunction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,15 @@ default <T, R> R execute(T t, ThrowableFunction<T, R> function) throws IllegalAr
4646
return execute(t, function, function::handlerException);
4747
}
4848

49+
default <V> ThrowableFunction<V, R> compose(ThrowableFunction<? super V, ? extends T> before) {
50+
AssertUtils.assertNotNull(before, "The 'before' must not be null");
51+
return (V v) -> apply(before.apply(v));
52+
}
53+
54+
default <V> ThrowableFunction<T, V> andThen(ThrowableFunction<? super R, ? extends V> after) {
55+
AssertUtils.assertNotNull(after, "The 'after' must not be null");
56+
return (T t) -> after.apply(apply(t));
57+
}
58+
4959

5060
}

0 commit comments

Comments
 (0)