Skip to content

Instantly share code, notes, and snippets.

@ohdoking
Created January 16, 2019 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohdoking/a215cf75818b24789b70e0bad5a45d20 to your computer and use it in GitHub Desktop.
Save ohdoking/a215cf75818b24789b70e0bad5a45d20 to your computer and use it in GitHub Desktop.
currying in java
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