package org.implab.gradle.common.utils;

import java.util.concurrent.CompletionException;
import java.util.function.Consumer;

public interface ThrowingConsumer<T, E extends Throwable> {
    void accept(T value) throws E;

    static <T> Consumer<T> guard(ThrowingConsumer<T,?> target) {
        return arg -> {
            try {
                target.accept(arg);
            } catch (Throwable err) {
                throw new CompletionException(err);
            }
        };
    }
}
