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