com.github.andyshao.util.function.ExceptionableBiFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.util.function;
import com.github.andyshao.lang.Convert;
import com.github.andyshao.util.stream.RuntimeExceptionFactory;
import java.util.Objects;
import java.util.function.BiFunction;
/**
*
*
* Title:
* Descript:
* Copyright: Copryright(c) May 28, 2019
* Encoding: UNIX UTF-8
*
* @author Andy.Shao
*
* @param argument type one
* @param argument type two
* @param return type
* @see BiFunction
*/
@FunctionalInterface
public interface ExceptionableBiFunction {
/**
* apply
* @param t left
* @param u right
* @return ret
* @throws Exception any error
*/
R apply(T t, U u) throws Throwable;
/**
* to {@link BiFunction}
* @param f error convert factory
* @return {@link BiFunction}
* @param left type
* @param right type
* @param return type
*/
static Convert, BiFunction> toBiFunction(RuntimeExceptionFactory> f) {
return input -> {
return (t, u) -> {
try {
return input.apply(t, u);
} catch (Throwable e) {
throw f.build(e);
}
};
};
}
/**
* to {@link BiFunction}
* @return {@link BiFunction}
* @param left type
* @param right type
* @param return type
*/
static Convert, BiFunction> toBiFunction() {
return toBiFunction(RuntimeExceptionFactory.DEFAULT);
}
/**
* and then
* @param after after
* @return new {@link ExceptionableBiFunction}
* @param return type
*/
default ExceptionableBiFunction andThen(ExceptionableFunction super R, ? extends V> after) {
Objects.requireNonNull(after);
return (T t, U u) -> after.apply(apply(t, u));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy