Function Currying is a concept of breaking a function with many arguments into many functions with single argument in such a way, that the output is same. In other words, its a technique of simplifying a multi-valued argument function into single-valued argument multi-functions.
Consider the example to clear the concept:
Currying breaks down higher order functions into a series of smaller cascaded functions which take in one argument and return a function except for the last cascaded function which returns the desired value.
Let there be a function which maps as
Currying the above function will produce
Thus maps from to a function which in turn maps from to
The above mathematical expression can also be represented as:
Below are some examples in Java to demonstrate Function Currying:
Example 1: Adding 2 numbers using Function Currying
Add 2, 3 :5
Example 2: Multiplying 2 numbers using Function Currying
Multiply 2, 3 :6
Example 3: Adding 3 numbers using Function Currying
Add 2, 3, 4 :9
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Trigonometric Functions in Java with Examples
- Shadowing of static functions in Java
- Java | Functions | Question 1
- Java | Functions | Question 2
- Java | Functions | Question 3
- Java | Functions | Question 4
- Java | Functions | Question 5
- Java | Functions | Question 6
- Java | Functions | Question 7
- Java | Functions | Question 8
- Java | Functions | Question 9
- Java | Functions | Question 10
- Java | Functions | Question 11
- Adding Labels to Method and Functions in Java
- Why is Scanner skipping nextLine() after use of other next functions?
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.util.BitSet class in Java with Examples | Set 1
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.Collections.frequency() in Java with Examples
- Java.util.Arrays.equals() in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.