Scala Currying & Partially Applied Functions
Currying is a concept rooted in mathematics and has also found it is way in computer science. Currying is a process of translating a function taking multiple arguments to a set of functions accepting only one argument. It is named after Haskell Curry! Currying in computer science is also done in a similar manner. You can read more on the background here. h(x)(y)(z) = f(x,y,z) h = curry(f) Let’s see how we can apply currying in Scala. Well, it’s not difficult to curry a function. See Below If you just pass addCurried(10) you would get an error. Which is not good and to be fair the function did require all the parameters to evaluate. Getting around this is simple with partially applied functions, these should not be confused with partial functions. See Below Another example of a partially applied function How about currying an existing function. That is also possible via Function.curried. It … Read more