package bjc.functypes; import java.util.function.Function; /** * A (possibly throwing) function associated with a closable resource * * @param The input type * @param The result type * @param The exception type */ public interface ClosableThrowFunction extends AutoCloseable, ThrowFunction { /** * Create a ClosableFunction from a {@link AutoCloseable} and a {@link Function} * * @param The input type * @param The result type * @param f The function * @param clos The AutoClosable * @return The closable function */ public static ClosableThrowFunction bindFunction(ThrowFunction f, AutoCloseable clos) { return new ClosableThrowFunction() { @Override public R apply(T t) throws E { return f.apply(t); } @Override public void close() throws Exception { clos.close(); } }; } }