All Downloads are FREE. Search and download functionalities are using the official Maven repository.

buckelieg.jdbc.fn.TryBiFunction Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2024- Anatoly Kutyakov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package buckelieg.jdbc.fn;

import static java.util.Objects.requireNonNull;

/**
 * Two-argument function with returned result that might throw an exception
 * 
There is no requirement that a new or distinct result be returned each time the function is invoked *
This is a functional interface whose functional method is {@link #apply(Object, Object)} * * @param first input argument type * @param second input argument type * @param result type * @param an exception type thrown */ @FunctionalInterface public interface TryBiFunction { /** * Represents a two-argument function which might throw an Exception * * @param input1 first argument * @param input2 second argument * @return output * @throws E an exception */ O apply(I1 input1, I2 input2) throws E; /** * Returns a composed function that first applies this function to * its input, and then applies the {@code after} function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param the type of output of the {@code after} function, and of the * composed function * @param after the function to apply after this function is applied * @return a composed function that first applies this function and then * applies the {@code after} function * @throws E an exception * @throws NullPointerException if after> is null */ default TryBiFunction andThen(TryFunction after) throws E { if(null == after) throw new NullPointerException("after Function must be provided"); return (I1 input1, I2 input2) -> after.apply(apply(input1, input2)); } /** * Returns reference of lambda expression * * @param tryBiFunction a function * @return lambda as {@link TryBiFunction} reference * @throws NullPointerException if tryBiFunction is null */ static TryBiFunction of(TryBiFunction tryBiFunction) { return requireNonNull(tryBiFunction, "Function must be provided"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy