Created
December 23, 2018 03:19
-
-
Save jcohen66/f2656856b7c83417850047f2b9dc2ff2 to your computer and use it in GitHub Desktop.
Lambda Function Composition #function #lambda #composition #apply
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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