【发布时间】:2021-10-23 14:44:21
【问题描述】:
在 Java 中有一个名为 BiFunction 的接口和 this source:
@FunctionalInterface
public interface BiFunction<T, U, R> {
R apply(T t, U u);
default <V> BiFunction<T, U, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after);
return (T t, U u) -> after.apply(apply(t, u));
}
}
oracle document 声明它是这样工作的:
表示一个接受两个参数并产生一个函数的函数 结果。这是 Function 的二元专业化。这是一个 功能方法为apply(Object, Object)的功能接口。
apply
R apply(T t, U u)将此函数应用于给定的参数。参数:t- 第一个函数参数u- 第二个函数参数 返回:函数结果
andThen
default <V> BiFunction<T,U,V> andThen(Function<? super R,? extends V> after)返回首先应用 this 的组合函数 函数到它的输入,然后将 after 函数应用于 结果。如果任一函数的求值引发异常,则为 转发给组合函数的调用者。类型参数:
V- after 函数和组合函数的输出类型 参数:after- 这个函数之后要应用的函数是 应用返回:首先应用此函数的组合函数 然后应用 after 函数抛出:NullPointerException- ifafter为空
我想知道如何在C#中将这个接口实现为类或扩展方法,C#中是否默认有这个类?
【问题讨论】:
-
可能是
System.Func<TArg0, TArg1, TResult>?
标签: java c# function equivalent