package org.xbib.logging.expression;

/**
 * A supplier which can throw an exception.
 */
@FunctionalInterface
public interface ExceptionSupplier<T, E extends Exception> {
    /**
     * Gets a result.
     *
     * @return the result
     * @throws E if an exception occurs
     */
    T get() throws E;

    default ExceptionRunnable<E> andThen(ExceptionConsumer<? super T, ? extends E> after) {
        return () -> after.accept(get());
    }

    @SuppressWarnings("overloads")
    default <R> ExceptionSupplier<R, E> andThen(ExceptionFunction<? super T, ? extends R, ? extends E> after) {
        return () -> after.apply(get());
    }
}
