Function
The function, functional interface (yes, it's called a function) was introduced mainly to translate one value into another. It is often used in mapping scenarios. It also contains default methods to combine multiple functions into one, and chain functions after one another.
The main function in the interface is called apply
, and it looks like this:
R apply(T);
It defines a return value, R
, and an input to the function. The idea is that the return value and input don't have to be of the same type.
The composition is handled by the compose
function, which also returns an instance of the interface, which means that you can chain compositions. The order is right to left; in other words, the argument function is applied before the calling function:
Function<V, R> compose(Function<V, T>);
Finally, the andThen
function allows you to chain functions after one another:
Function<T, V> andThen(Function<R, V>);
In the following...