Skip to content

Instantly share code, notes, and snippets.

@jcohen66
Created December 23, 2018 03:19
Show Gist options
  • Save jcohen66/f2656856b7c83417850047f2b9dc2ff2 to your computer and use it in GitHub Desktop.
Save jcohen66/f2656856b7c83417850047f2b9dc2ff2 to your computer and use it in GitHub Desktop.
Lambda Function Composition #function #lambda #composition #apply
/**
* This translates to g(f(x))
*/
Function<Integer, Integer> f = x -> x + 1;
Function<Integer, Integer> g = x -> x * 2;
Function<Integer, Integer> h = f.andThen(g);
int res2 = h.apply(1);
System.out.println(res2);
/**
* This translates to f(g(x))
*/
Function<Integer, Integer> f = x -> x + 1;
Function<Integer, Integer> g = x -> x * 2;
Function<Integer, Integer> h = f.compose(g);
int res2 = h.apply(1);
System.out.println(res2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment