org.ethelred.util.function.CheckedConsumer Maven / Gradle / Ivy
The newest version!
/* (C) 2024 */
package org.ethelred.util.function;
import java.util.function.Consumer;
/**
* Checked wrapper for a Consumer.
*
* @param The consumed type
* @param A checked exception type that is thrown by the operation
*/
public interface CheckedConsumer {
void accept(T t) throws E;
default Consumer asUnchecked() {
return t -> {
try {
accept(t);
} catch (Throwable e) {
throw new WrappedCheckedException(e);
}
};
}
static Consumer unchecked(CheckedConsumer checkedConsumer) {
return checkedConsumer.asUnchecked();
}
}