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