001package Torello.Java.Function;
002
003import java.util.function.Function;
004
005/**
006 * Function-Pointer
007 * <SPAN CLASS=TJF>Input:</SPAN> {@code double, T}
008 * <SPAN CLASS=TJF>Output:</SPAN> {@code R}.
009 * 
010 * <BR /><BR />
011 * <EMBED CLASS='external-html' DATA-FILE-ID=PRIMITIVE_T_FUNC>
012 * <EMBED CLASS="globalDefs" DATA-Primitive=double>
013 * 
014 * @param <T> The type of the second input-parameter.
015 * @param <R> The type of the function-output.
016 */
017@FunctionalInterface
018public interface DoubleTFunction<T, R>
019{
020    /**
021     * Applies this function to the given arguments.
022     * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=FUNC_INTER_METH>
023     *
024     * @param d The double (first) argument to the function.
025     * @param t The (second) argument to the function.
026     * @return The function result.  Result shall be of type {@code 'R'}
027     */
028    public R apply(double d, T t);
029
030    /**
031     * Returns a composed function that first applies {@code 'this'} function to its input, and
032     * then applies the {@code 'after'} function to the result. If evaluation of either function
033     * throws an exception, it is relayed to the caller of the composed function.
034     * 
035     * @param <V> the output-type of the {@code 'after'} function, and also of the (returned)
036     * {@code 'composed'} function.
037     * 
038     * @param after The function to apply, after this function is applied.
039     * 
040     * @return a composed function that first applies {@code 'this'} function and then applies the
041     * {@code 'after'} function
042     * 
043     * @throws NullPointerException if null is passed to parameter {@code 'after'}.
044     */
045    public default <V> DoubleTFunction<T, V> andThen(Function<? super R, ? extends V> after)
046    {
047        if (after == null) throw new NullPointerException
048            ("null has been passed to parameter 'after'");
049
050        return (double d, T t) -> after.apply(this.apply(d, t));
051    }
052}