
hm.binkley.util.function.ThrowingFunction Maven / Gradle / Ivy
The newest version!
package hm.binkley.util.function;
import javax.annotation.Nonnull;
import java.util.function.Function;
/**
* {@code ThrowingFunction} is a throwing look-a=like of {@link Function}. It cannot be a
* {@code Function} as it takes throwing versions of functions. Otherwise it is a faithful
* reproduction.
*
* @author B. K. Oxley (binkley)
*/
@SuppressWarnings({"UnusedDeclaration", "JavaDoc"})
@FunctionalInterface
public interface ThrowingFunction {
/** @see Function#apply(Object) */
R apply(final T t)
throws E, InterruptedException;
/** @see Function#compose(Function) */
@Nonnull
default ThrowingFunction compose(
@Nonnull final ThrowingFunction super V, ? extends T, E> before) {
return (V v) -> apply(before.apply(v));
}
/** @see Function#andThen(Function) */
@Nonnull
default ThrowingFunction andThen(
@Nonnull final ThrowingFunction super R, ? extends V, E> after) {
return (T t) -> after.apply(apply(t));
}
/** @see Function#identity() */
@Nonnull
static ThrowingFunction identity() {
return t -> t;
}
/** Creates a facade {@code Function} wrapping this throwing one. */
default Function asFunction(
final Defer defer) {
return t -> defer.as(() -> apply(t));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy