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