package java.util.function;
import java.util.Objects;
/**
* 表示接收两个参数返回一个结果的函数。
* 这是 {@link Function}的特殊化
*
* <p>这是一个 <a href="package-summary.html">函数式接口</a>
* 它的函数式方法是 {@link #apply(Object, Object)}.
*
* @param <T> the type of the first argument to the function
* @param <U> the type of the second argument to the function
* @param <R> the type of the result of the function
*
* @see Function
* @since 1.8
*/
@FunctionalInterface
public interface BiFunction<T, U, R> {
/**
* 将给定的参数应用这个函数
*
* @param t the first function argument
* @param u the second function argument
* @return the function result
*/
R apply(T t, U u);
/**
* 返回一个组合函数,它首先将该函数应用于它的输入,然后将 {@code after}
* 函数应用于结果。如果任一函数的评估抛出异常,
* 则将其传递给组合函数的调用方 。
*
* @param <V> 函数的输出类型 {@code after} ,以及组合函数的类型。
* @param after 应用该函数后的函数
* @return 一个组合的函数,首先应用这个函数,然后应用{@code after} 函数。
* @throws NullPointerException if after is null
*/
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));
}
}
import java.util.Objects;
/**
* 表示接收两个参数返回一个结果的函数。
* 这是 {@link Function}的特殊化
*
* <p>这是一个 <a href="package-summary.html">函数式接口</a>
* 它的函数式方法是 {@link #apply(Object, Object)}.
*
* @param <T> the type of the first argument to the function
* @param <U> the type of the second argument to the function
* @param <R> the type of the result of the function
*
* @see Function
* @since 1.8
*/
@FunctionalInterface
public interface BiFunction<T, U, R> {
/**
* 将给定的参数应用这个函数
*
* @param t the first function argument
* @param u the second function argument
* @return the function result
*/
R apply(T t, U u);
/**
* 返回一个组合函数,它首先将该函数应用于它的输入,然后将 {@code after}
* 函数应用于结果。如果任一函数的评估抛出异常,
* 则将其传递给组合函数的调用方 。
*
* @param <V> 函数的输出类型 {@code after} ,以及组合函数的类型。
* @param after 应用该函数后的函数
* @return 一个组合的函数,首先应用这个函数,然后应用{@code after} 函数。
* @throws NullPointerException if after is null
*/
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));
}
}