com.github.markozajc.ef.biconsumer.except.EBiConsumer Maven / Gradle / Ivy
package com.github.markozajc.ef.biconsumer.except;
import static com.github.markozajc.ef.Utilities.asUnchecked;
import java.util.function.BiConsumer;
/**
* Variant of {@link BiConsumer} capable of throwing a generic {@link Throwable}.
*
* @author Marko Zajc
*
* @param
* the type of the first argument to the operation
* @param
* the type of the second argument to the operation
* @param
* {@link Throwable} type
*/
@FunctionalInterface
public interface EBiConsumer extends BiConsumer {
@Override
default void accept(T t, U u) {
try {
acceptChecked(t, u);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
}
/**
* Same as {@link #accept(Object, Object)}, but throws a checked exception.
*
* @param t
* the first input argument
* @param u
* the second input argument
*
* @throws E
* the defined exception type
*/
void acceptChecked(T t, U u) throws E;
}