1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package Torello.Java.Function;

import java.util.function.Function;

/**
 * Function-Pointer
 * <SPAN CLASS=TJF>Input:</SPAN> {@code double, T}
 * <SPAN CLASS=TJF>Output:</SPAN> {@code R}.
 * 
 * <BR /><BR />
 * <EMBED CLASS='external-html' DATA-FILE-ID=PRIMITIVE_T_FUNC>
 * <EMBED CLASS="globalDefs" DATA-Primitive=double>
 * 
 * @param <T> The type of the second input-parameter.
 * @param <R> The type of the function-output.
 */
@FunctionalInterface
public interface DoubleTFunction<T, R>
{
    /**
     * Applies this function to the given arguments.
     * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=FUNC_INTER_METH>
     *
     * @param d The double (first) argument to the function.
     * @param t The (second) argument to the function.
     * @return The function result.  Result shall be of type {@code 'R'}
     */
    public R apply(double d, T t);

    /**
     * Returns a composed function that first applies {@code 'this'} function to its input, and
     * then applies the {@code 'after'} function to the result. If evaluation of either function
     * throws an exception, it is relayed to the caller of the composed function.
     * 
     * @param <V> the output-type of the {@code 'after'} function, and also of the (returned)
     * {@code 'composed'} function.
     * 
     * @param after The function to apply, after this function is applied.
     * 
     * @return a composed function that first applies {@code 'this'} function and then applies the
     * {@code 'after'} function
     * 
     * @throws NullPointerException if null is passed to parameter {@code 'after'}.
     */
    public default <V> DoubleTFunction<T, V> andThen(Function<? super R, ? extends V> after)
    {
        if (after == null) throw new NullPointerException
            ("null has been passed to parameter 'after'");

        return (double d, T t) -> after.apply(this.apply(d, t));
    }
}