001package Torello.Java.Function;
002
003import java.util.function.Function;
004
005/**
006 * <CODE>ByteTFunction Documentation.</CODE><BR /><BR />
007 * <EMBED CLASS="external-html" DATA-FILE-ID="PRIMTFUNC">
008 * <EMBED CLASS="globalDefs" DATA-Primitive=byte>
009 * @param <T> The type of the second input-parameter.
010 * @param <R> The type of the function-output.
011 */
012@FunctionalInterface
013public interface ByteTFunction<T, R>
014{
015    /**
016     * Applies this function to the given arguments.
017     * @param b The byte (first) argument to the function.
018     * @param t The (second) argument to the function.
019     * @return The function result.  Result shall be of type {@code 'R'}
020     */
021    public R apply(byte b, T t);
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     * 
033     * @return a composed function that first applies {@code 'this'} function and then applies the
034     * {@code 'after'} function
035     * 
036     * @throws NullPointerException if null is passed to parameter {@code 'after'}.
037     */
038    public default <V> ByteTFunction<T, V> andThen(Function<? super R, ? extends V> after)
039    {
040        if (after == null) throw new NullPointerException
041            ("null has been passed to parameter 'after'");
042
043        return (byte b, T t) -> after.apply(this.apply(b, t));
044    }
045}