package bjc.functypes; import java.util.function.Function; /** * A function associated with a closable resource * * @param The input type * @param The result type */ public interface ClosableFunction extends AutoCloseable, Function { /** * 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 ClosableFunction bindFunction(Function f, AutoCloseable clos) { return new ClosableFunction() { @Override public R apply(T t) { return f.apply(t); } @Override public void close() throws Exception { clos.close(); } }; } }