A partial function is a function that is valid only for a subset of the values โโof those types that you could pass to it. For example:
val root: PartialFunction[Double,Double] = { case d if (d >= 0) => math.sqrt(d) } scala> root.isDefinedAt(-1) res0: Boolean = false scala> root(3) res1: Double = 1.7320508075688772
This is useful if you have something that knows how to check if a function is defined. Collect for example:
scala> List(0.5, -0.2, 4).collect(root)
This does not help you place two arguments where you really want it.
In contrast, a partially applied function is a function in which some of its arguments are already filled.
def add(i: Int, j: Int) = i + j val add5 = add(_: Int,5)
Now you only need one argument - the thing is to add 5 in - instead of two:
scala> add5(2) res3: Int = 7
In this example, you can see how to use it.
But if you need to specify these two arguments, it wonโt happen anyway - let's say you want to use map , for example, and you need to give it the function of one argument, but you want to add two different things to it. Well then you can
val addTupled = (add _).tupled
which will partially apply the function (in fact, just create a function from the method since nothing was filled), and then combine the individual arguments into a tuple. Now you can use this in places where one argument is required (assuming the type is correct):
scala> List((1,2), (4,5), (3,8)).map(addTupled) res4: List[Int] = List(3, 9, 11)
In contrast, currying again; it turns functions of the form (A,B) => C into A => B => C That is, if a function of several arguments is specified, it will create a chain of functions, each of which will take one argument and return the chain even shorter (you can think of it as partial application of one argument at a time).
val addCurried = (add _).curried scala> List(1,4,3).map(addCurried) res5: List[Int => Int] = List(<function1>, <function1>, <function1>) scala> res5.head(2)