Currying Functions in Java with Examples Last Updated : 18 Sep, 2018 Comments Improve Suggest changes Like Article Like Report 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. For example: Let there be a function which maps as f:(u, v) -> w Currying the above function will produce g:(u->(v->w)) Thus g maps from u to a function which in turn maps from v to w The above mathematical expression can also be represented as: {g(u)}(v)=f(u, v) Hence, curry(f) = g Below are some examples in Java to demonstrate Function Currying: Example 1: Adding 2 numbers using Function Currying Java // Java Program to demonstrate Function Currying import java.util.function.Function; public class GFG { public static void main(String args[]) { // Using Java 8 Functions // to create lambda expressions for functions // and with this, applying Function Currying // Curried Function for Adding u & v Function<Integer, Function<Integer, Integer> > curryAdder = u -> v -> u + v; // Calling the curried functions // Calling Curried Function for Adding u & v System.out.println("Add 2, 3 :" + curryAdder .apply(2) .apply(3)); } } Output: Add 2, 3 :5 Example 2: Multiplying 2 numbers using Function Currying Java // Java Program to demonstrate Function Currying import java.util.function.Function; public class GFG { public static void main(String args[]) { // Using Java 8 Functions // to create lambda expressions for functions // and with this, applying Function Currying // Curried Function for Multiplying u & v Function<Integer, Function<Integer, Integer> > curryMulti = u -> v -> u * v; // Calling the curried functions // Calling Curried Function for Multiplying u & v System.out.println("Multiply 2, 3 :" + curryMulti .apply(2) .apply(3)); } } Output: Multiply 2, 3 :6 Example 3: Adding 3 numbers using Function Currying Java // Java Program to demonstrate Function Currying import java.util.function.Function; public class GFG { public static void main(String args[]) { // Using Java 8 Functions // to create lambda expressions for functions // and with this, applying Function Currying // Curried Function for Adding u, v & w Function<Integer, Function<Integer, Function<Integer, Integer> > > triadder = u -> w -> v -> u + w + v; // Calling the curried functions // Calling Curried Function for Adding u, v & w System.out.println("Add 2, 3, 4 :" + triadder .apply(2) .apply(3) .apply(4)); } } Output: Add 2, 3, 4 :9 Comment More infoAdvertise with us Next Article Currying Functions in Java with Examples P psil123 Follow Improve Article Tags : Misc Java Programming Language Java-Functions java-advanced Java 8 +2 More Practice Tags : JavaMisc Similar Reads Trigonometric Functions in Java with Examples The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Java.lang.Math.sin() Method : is an inbuilt method which returns the sine of the value passed as an argument. The value passed in this func 3 min read Functional Programming in Java with Examples So far Java was supporting the imperative style of programming and object-oriented style of programming. The next big thing what java has been added is that Java has started supporting the functional style of programming with its Java 8 release. In this article, we will discuss functional programmin 8 min read Closures in Java with Examples A method is a collection of statements that perform some specific task and return the result to the caller. A method can perform some specific task without returning anything. Methods allow us to reuse the code without retyping the code. In Java, every method must be part of some class that is diffe 5 min read Java.util.function.DoubleBinaryOperator interface with Examples The DoubleBinaryOperator interface was introduced in Java 8. It represents an operation on two double values and returns the result as a double value. It is a functional interface and thus can be used as a lambda expression or in a method reference. It is mostly used when the operation needs to be e 2 min read Float compare() Method in Java with Examples The compare() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(float f1, float f2)Parameters: The f 2 min read IntFunction Interface in Java with Examples The IntFunction Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in an int-valued argument and produces a result of type R. This functional interface takes in only one gener 1 min read DoubleFunction Interface in Java with Examples The DoubleFunction Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in a double-valued argument and produces a result of type R. This functional interface takes in only one 1 min read IntConsumer Interface in Java with Examples The IntConsumer Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in one int-valued argument but does not return any value. The lambda expression assigned to an object of Int 3 min read Java.util.function.BiPredicate interface in Java with Examples The BiPredicate<T, V> interface was introduced in JDK 8. This interface is packaged in java.util.function package. It operates on two objects and returns a predicate value based on that condition. It is a functional interface and thus can be used in lambda expression also. public interface BiP 2 min read Java.util.function.DoublePredicate interface in Java with Examples The DoublePredicate interface was introduced in JDK 8. This interface is packaged in java.util.function package. It operates on a Double object and returns a predicate value based on a condition. It is a functional interface and thus can be used in lambda expression also. public interface DoublePred 2 min read Like