com.seeq.utilities.Wrapping Maven / Gradle / Ivy
The newest version!
package com.seeq.utilities;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Consumer;
import java.util.function.Function;
public class Wrapping {
@FunctionalInterface
public interface IoFunction {
R apply(T t);
}
public static Function function(IoFunction delegate) {
return delegate::apply;
}
@FunctionalInterface
public interface IoConsumer {
void accept(T t) throws IOException;
}
public static Consumer consumer(IoConsumer delegate) {
return input -> {
try {
delegate.accept(input);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
@FunctionalInterface
public interface IoRunnable {
void run() throws IOException;
}
public static Runnable runnable(IoRunnable delegate) {
return () -> {
try {
delegate.run();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
}