package io.delphiplatform.api.util;

public class FunctionUtils {

    @FunctionalInterface
    public interface FunctionThrowing<T, R> {

        R apply(T t) throws Exception;
    }

    public static <T, R> R applyWrappedInRuntimeEx(FunctionThrowing<T, R> f, T arg, String exceptionMessage) {
        try {
            return f.apply(arg);
        } catch (Exception e) {
            throw new RuntimeException(exceptionMessage, e);
        }
    }

    public static void threadSleep(long delay) {
        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            //ignore
        }
    }
}
