Java Lambda - Function compose example

Function compose returns a composed function that first applies the before function to its input, and then applies this function to the result.


compose has the following syntax.

default <V> Function<V,R> compose(Function<? super V,? extends T> before)


The following example shows how to use compose.

import java.util.function.Function;
/*from   w  w w  . j  av a 2s .  co  m*/
public class Main {

  public static void main(String[] args) {
    Function<Integer,String> converter = (i)-> Integer.toString(i);
    Function<String, Integer> reverse = (s)-> Integer.parseInt(s);

The code above generates the following result.