|
| 1 | +package org.scijava.ops.core; |
| 2 | + |
| 3 | +import java.util.Objects; |
| 4 | +import java.util.function.Function; |
| 5 | + |
| 6 | +/** |
| 7 | + * Represents a function that accepts three arguments and produces a result. |
| 8 | + * This is the four-arity specialization of {@link Function}. |
| 9 | + * |
| 10 | + * <p> |
| 11 | + * This is a <a href="package-summary.html">functional interface</a> whose |
| 12 | + * functional method is {@link #apply(Object, Object)}. |
| 13 | + * |
| 14 | + * @param <I1> |
| 15 | + * the type of the first argument to the function |
| 16 | + * @param <I2> |
| 17 | + * the type of the second argument to the function |
| 18 | + * @param <I3> |
| 19 | + * the type of the third argument to the function |
| 20 | + * @param <I4> |
| 21 | + * the type of the fourth argument to the function |
| 22 | + * @param <O> |
| 23 | + * the type of the output of the function |
| 24 | + * |
| 25 | + * @see Function |
| 26 | + * @since 1.8 |
| 27 | + */ |
| 28 | +@FunctionalInterface |
| 29 | +public interface QuadFunction<I1, I2, I3, I4, O> { |
| 30 | + |
| 31 | + /** |
| 32 | + * Applies this function to the given arguments. |
| 33 | + * |
| 34 | + * @param t |
| 35 | + * the first function argument |
| 36 | + * @param u |
| 37 | + * the second function argument |
| 38 | + * @param v |
| 39 | + * the third function argument |
| 40 | + * @param w |
| 41 | + * the fourth function argument |
| 42 | + * @return the function output |
| 43 | + */ |
| 44 | + O apply(I1 t, I2 u, I3 v, I4 w); |
| 45 | + |
| 46 | + /** |
| 47 | + * Returns a composed function that first applies this function to its input, |
| 48 | + * and then applies the {@code after} function to the result. If evaluation of |
| 49 | + * either function throws an exception, it is relayed to the caller of the |
| 50 | + * composed function. |
| 51 | + * |
| 52 | + * @param <O2> |
| 53 | + * the type of output of the {@code after} function, and of the |
| 54 | + * composed function |
| 55 | + * @param after |
| 56 | + * the function to apply after this function is applied |
| 57 | + * @return a composed function that first applies this function and then applies |
| 58 | + * the {@code after} function |
| 59 | + * @throws NullPointerException |
| 60 | + * if after is null |
| 61 | + */ |
| 62 | + default <O2> QuadFunction<I1, I2, I3, I4, O2> andThen(Function<? super O, ? extends O2> after) { |
| 63 | + Objects.requireNonNull(after); |
| 64 | + return (I1 in1, I2 in2, I3 in3, I4 in4) -> after.apply(apply(in1, in2, in3, in4)); |
| 65 | + } |
| 66 | +} |
0 commit comments