Partial Application
In this page:
Partial Application
Partial application fixes some of a function's arguments upfront, producing a new function that only needs the remaining ones, using the _ placeholder for unfixed positions, like add(5, _: Int). This is closely related to currying but works on ordinary (non-curried) multi-parameter functions too. It's a way to specialize a general function into a more specific one without writing new code.
Note: Partial application with _ works on regular multi-parameter functions, not just curried ones with multiple parameter lists.
Example: Partial Application
object Main extends App {
def add(a: Int, b: Int): Int = a + b
val addFive: Int => Int = add(5, _: Int)
println(addFive(10))
println(addFive(20))
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: