Scala – Currying function

A Currying function is a function which has multiple parameter list 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 names and want to add prefix and suffix to each name. Let’s see how we can do this with a curried function.

Scala-Currying

In the above example, the function “addPrefixSuffix” is a curried function which accepts three arguments such as prefix, suffix and name. So in the “main” function, I pass only two arguments to this so it will yield another function to accept the missing parameter(name).

Advertisements