Currying is taking a function with n parameters and returning a function with one parameter that returns a function with one parameter until you reach the n parameters of the original function and then you get the result.
The following method gets the curried version of a method with the signature:
And returns the curried version:
Then we can use it to get curried versions of such methods:
And use them like this:
In the following example we use the curried versions to first add 1 and then multiply by 2 all the elements of a stream
We can use currying as a form of partial application, imagine we have the following method:
This method returns the http status or part of the exception if any was thrown.
If we use it like that we would have to be setting all the parameters everytime we want to use the function, but if we have a curried version:
We could then set the parameters we have:
And then just fill the renaming parameter when using the function: