-
Notifications
You must be signed in to change notification settings - Fork 5
/
TriFunction.java
48 lines (44 loc) · 1.74 KB
/
TriFunction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.utils;
import java.util.Objects;
import java.util.function.Function;
/**
* Enhancement of {@link Function} and {@link java.util.function.BiFunction} that accepts three
* arguments and produces a result.
*
* @param <A> the type of the first argument to the function
* @param <B> the type of the second argument to the function
* @param <C> the type of the third argument to the function
* @param <R> the type of the result of the function
*/
@FunctionalInterface
public interface TriFunction<A, B, C, R> {
/**
* Applies this function to the given arguments.
*
* @param a the first function argument
* @param b the second function argument
* @param c the third function argument
* @return the function result
*/
R apply(A a, B b, C c);
/**
* Returns a composed function that first applies this function to its input, and then applies the
* {@code after} function to the result. If evaluation of either function throws an exception, it
* is relayed to the caller of the composed function.
*
* @param <V> the type of output of the {@code after} function, and of the composed function
* @param after the function to apply after this function is applied
* @return a composed function that first applies this function and then applies the {@code after}
* function
* @throws NullPointerException if after is null
*/
default <V> TriFunction<A, B, C, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after);
return (final A a, final B b, final C c) -> after.apply(apply(a, b, c));
}
}