001package Torello.Java.Function;
002
003import java.util.function.Function;
004
005/**
006 * Function-Pointer
007 * <SPAN CLASS=TJF>Input:</SPAN> {@code int, int, char}
008 * <SPAN CLASS=TJF>Output:</SPAN> {@code R}.
009 * 
010 * <BR /><BR />
011 * Primitive's Extension to Java's {@code java.util.function.*} package.
012 * <BR /><BR />This {@code FunctionalInterface} has an {@code apply(...)} method which accepts
013 * three primitives: two {@code int}-primitives, and one {@code char}.
014 * @param <R> The type of the function-output.
015 */
016@FunctionalInterface
017public interface IntIntCharFunc<R>
018{
019    /**
020     * Applies a user-provided function to input aruments, returning a result of type {@code R}
021     * @param i1 The first integer-parameter.
022     * @param i2 The second integer-parameter.
023     * @param c A {@code 'char'} parameter.
024     * @return The function result.  Result shall be of type {@code 'R'}
025     */
026    public R apply(int i1, int i2, char c);
027
028    /**
029     * Returns a composed function that first applies {@code 'this'} function to its input, and
030     * then applies the {@code 'after'} function to the result. If evaluation of either function
031     * throws an exception, it is relayed to the caller of the composed function.
032     * 
033     * @param <V> The output-type of the {@code 'after'} function, and also of the (returned)
034     * {@code 'composed'} function.
035     * 
036     * @param after The function to apply, after this function is applied.
037     * @throws NullPointerException This throws if null is passed to {@code 'after'}.
038     */
039    public default <V> IntIntCharFunc<V> andThen(Function<R, V> after)
040    {
041        if (after == null) throw new NullPointerException
042            ("null has been passed to parameter 'after'");
043
044        return (int i1, int i2, char c) -> after.apply(this.apply(i1, i2, c));
045    }
046}