ExIntBinaryOperator.java

package net.dapete.exceptional.function;

import net.dapete.exceptional.ExWrap;
import org.jspecify.annotations.NonNull;

import java.util.function.IntBinaryOperator;

/**
 * Equivalent of an {@link java.util.function.IntBinaryOperator} that can throw exceptions.
 *
 * @param <E> the type of exception thrown
 */
@FunctionalInterface
public interface ExIntBinaryOperator<E extends Exception> extends Wrappable<IntBinaryOperator> {

    /**
     * Applies this operator to the given operands.
     *
     * @param left  the first operand
     * @param right the second operand
     * @return the operator result
     * @throws E potentially
     */
    int applyAsInt(int left, int right) throws E;

    @Override
    default @NonNull IntBinaryOperator wrap() {
        return (left, right) -> ExWrap.wrap(() -> applyAsInt(left, right));
    }

}