001/*
002 * ============================================================================
003 * Copyright © 2002-2023 by Thomas Thrien.
004 * All Rights Reserved.
005 * ============================================================================
006 *
007 * Licensed to the public under the agreements of the GNU Lesser General Public
008 * License, version 3.0 (the "License"). You may obtain a copy of the License at
009 *
010 *      http://www.gnu.org/licenses/lgpl.html
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015 * License for the specific language governing permissions and limitations
016 * under the License.
017 */
018
019package org.tquadrat.foundation.function.tce;
020
021import static org.apiguardian.api.API.Status.STABLE;
022import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument;
023
024import org.apiguardian.api.API;
025import org.tquadrat.foundation.annotation.ClassVersion;
026
027/**
028 *  The TCE version of the interface
029 *  {@link org.tquadrat.foundation.function.TriFunction}
030 *  that represents a function that accepts three arguments and produces a
031 *  result.<br>
032 *  <br>Different from the method
033 *  {@link org.tquadrat.foundation.function.TriFunction#apply(Object, Object, Object) Function.apply()}
034 *  the method
035 *  {@link #apply(Object, Object, Object)}
036 *  of this interface declares to throw a
037 *  {@linkplain Exception checked exception}.<br>
038 *  <br>This is a functional interface whose functional method is
039 *  {@link #apply(Object, Object, Object)}.
040 *
041 *  @param  <A> The type of the first argument to the function.
042 *  @param  <B> The type of the second argument to the function.
043 *  @param  <C> The type of the third argument to the function.
044 *  @param  <R> The type of the result of the function.
045 *
046 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
047 *  @version $Id: TCETriFunction.java 1060 2023-09-24 19:21:40Z tquadrat $
048 *  @since 0.0.5
049 *
050 *  @UMLGraph.link
051 */
052@SuppressWarnings( "ProhibitedExceptionDeclared" )
053@FunctionalInterface
054@ClassVersion( sourceVersion = "$Id: TCETriFunction.java 1060 2023-09-24 19:21:40Z tquadrat $" )
055@API( status = STABLE, since = "0.0.5" )
056public interface TCETriFunction<A,B,C,R>
057{
058        /*---------*\
059    ====** Methods **==========================================================
060        \*---------*/
061    /**
062     *  Applies this function to the given arguments.
063     *
064     *  @param  firstArgument   The first function argument.
065     *  @param  secondArgument  The second function argument.
066     *  @param  thirdArgument   The third function argument.
067     *  @return The function result.
068     *  @throws Exception   Something went wrong.
069     */
070    @SuppressWarnings( "ProhibitedExceptionDeclared" )
071    public R apply( final A firstArgument, final B secondArgument, final C thirdArgument ) throws Exception;
072
073    /**
074     *  Returns a composed function that first applies this function to its
075     *  input, and then applies the after function to the result. If evaluation
076     *  of either function throws an exception, it is relayed to the caller of
077     *  the composed function.
078     *
079     *  @param  <R1>    The type of the output of the {@code after} function,
080     *      and of the composed function.
081     *  @param  after   The function to apply after this function is applied.
082     *  @return A composed function that first applies this function and then
083     *      applies the {@code after} function.
084     *
085     *  @since 0.1.0
086     */
087    @API( status = STABLE, since = "0.1.0" )
088    public default <R1> TCETriFunction<A,B,C,R1> andThen( final TCEFunction<? super R, ? extends R1> after )
089    {
090        final TCETriFunction<A,B,C,R1> retValue = ( A firstArgument, B secondArgument, C thirdArgument ) -> requireNonNullArgument( after, "after" )
091            .apply( apply( firstArgument, secondArgument, thirdArgument ) );
092
093        //---* Done *----------------------------------------------------------
094        return retValue;
095    }   //  andThem()
096}
097//  interface TCETriFunction
098
099/*
100 *  End of File
101 */