Partial function implementation


In book ‘Functional Programming In Scala’, following function is to be implemented :

def partial1[A,B,C](a: A, f: (A,B) => C): B => C

My implementation is as follows

def partial1[A,B,C](a: A, f: (A,B) => C): B => C = {
val g = (b: B) => f(a, b)

Book states that the function is called partial as it is being applied to some but not all of its required

I am not able to relate this statement to the implementation above.
Is implementation wrong?


Your implementation is right (though though some unnecessary ceremony: for any

val foo = x

you can just write x, so you can replace

val g = (b: B) => f(a, b)

with (b: B) => f(a, b)

Also note that usually a “partially applied” function is something other than a partial function.

partial1 partially applies the function: given a function f: (A, B) => C, the method partial1 uses argument a to partially apply f, so that you now get a function that still needs to be applied to some B (but no longer to some A)


So basically a call to partial1 gives a function which has been restricted to a particular value of A, hence the name.