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