mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 07:18:23 +08:00
feat(function): 添加 andThen 与 compose 方法
。
This commit is contained in:
@@ -17,6 +17,7 @@ public interface PreparedSQLUpdateAction<T extends Number> extends SQLUpdateActi
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedSQLUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
PreparedSQLUpdateAction<T> setParams(@Nullable Iterable<Object> params);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public interface PreparedSQLUpdateBatchAction<T extends Number> extends SQLActio
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link SQLUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number> PreparedSQLUpdateBatchAction<N> returnGeneratedKeys(Class<N> keyTypeClass);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ public interface SQLUpdateAction<T extends Number> extends SQLAction<T> {
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link SQLUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number> SQLUpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SQLFunction<T, R> {
|
||||
@@ -11,4 +12,23 @@ public interface SQLFunction<T, R> {
|
||||
@Nullable
|
||||
R apply(@NotNull T t) throws SQLException;
|
||||
|
||||
default <V> SQLFunction<V, R> compose(@NotNull SQLFunction<? super V, ? extends T> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return (V v) -> {
|
||||
T t = before.apply(v);
|
||||
if (t == null) return null;
|
||||
else return apply(t);
|
||||
};
|
||||
}
|
||||
|
||||
default <V> SQLFunction<T, V> then(@NotNull SQLFunction<? super R, ? extends V> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (T t) -> {
|
||||
R r = apply(t);
|
||||
if (r == null) return null;
|
||||
else return after.apply(r);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user