Scala – Currying function

A Currying function is a function which has multiple parameter lists but can be called with few arguments and yields another function which accepts the missing parameters as its arguments.

Consider that we have a list of names and want to add prefix and suffix to each name. Let’s see how we can do this with a curried function.


In the above example, the method “addPrefixSuffix” is a curried function which takes three fields such as prefix, suffix, and name. But in the ‘main’ method, we pass prefix and suffix only. As the parameters partially applied to the method ‘addPrefixSuffix’, it will return another function to take the missing argument (name) and we pass the partial/curried function to the method ‘modifyNames’ and inside this method, we pass the missing argument.