BiFunction andThen example
Description
Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
Syntax
andThen
has the following syntax.
default <V> BiFunction<T,U,V> andThen(Function<? super R,? extends V> after)
Example
The following example shows how to use andThen
.
import java.util.function.BiFunction;
import java.util.function.Function;
/*from ww w.j ava2 s . co m*/
public class Main {
public static void main(String[] args) {
BiFunction<String, String,String> bi = (x, y) -> {
return x + y;
};
Function<String,String> f = x-> x+" new";
System.out.println(bi.andThen(f).andThen(f).apply("java2s.com", " tutorial"));
}
}
The code above generates the following result.
Home »
Java Lambda »
java.util.function Reference »
Java Lambda »
java.util.function Reference »