
org.whaka.util.function.Function3 Maven / Gradle / Ivy
package org.whaka.util.function;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
/**
* Equal to {@link BiFunction} but with 3 arguments.
*
* @see #toFunction(Function3)
* @see #toBiFunction(Function3)
*/
@FunctionalInterface
public interface Function3 {
R apply(A a, B b, C c);
/**
* Convert specified function to the {@link Function} were all arguments are represented
* as a single {@link Tuple3} instance.
*/
static Function, R> toFunction(Function3 delegate) {
return e -> delegate.apply(e._1, e._2, e._3);
}
/**
* Convert specified function to the {@link BiFunction} were all arguments except the thirst one are represented
* as a single {@link Tuple2} instance.
*/
static BiFunction, R> toBiFunction(Function3 delegate) {
return (a,e) -> delegate.apply(a, e._1, e._2);
}
default Function3 andThen(Function super R, ? extends V> then) {
Objects.requireNonNull(then, "Chained function cannot be null!");
return (a,b,c) -> then.apply(apply(a, b, c));
}
}