Created
January 16, 2019 09:26
-
-
Save ohdoking/a215cf75818b24789b70e0bad5a45d20 to your computer and use it in GitHub Desktop.
currying in java
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
public void currying() { | |
// Create a function that adds 2 integers | |
BiFunction<Integer,Integer,Integer> adder = ( a, b ) -> a + b ; | |
// And a function that takes an integer and returns a function | |
Function<Integer,Function<Integer,Integer>> currier = a -> b -> adder.apply( a, b ) ; | |
// Call apply 4 to currier (to get a function back) | |
Function<Integer,Integer> curried = currier.apply( 4 ) ; | |
// Results | |
System.out.printf( "Curry : %d\n", curried.apply( 3 ) ) ; // ( 4 + 3 ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment