O'Reilly logo

Pragmatic Scala by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Partially Applied Functions

When you invoke a function, you’re said to be applying the function to the arguments. If you pass all the expected arguments, you’ve fully applied the function and you get the result of the application or call. However, if you pass fewer than all the required parameters, you get back another function. This function is called a partially applied function. This gives the convenience of binding some arguments and leaving the rest to be filled in later. Here’s an example:

FunctionValuesAndClosures/Log.scala
 
import​ java.util.Date
 
 
def​ log(date: Date, message: ​String​) = {
 
//...
 
println(s​"$date ---- $message"​)
 
}
 
 
val​ date = ​new​ Date(1420095600000L)
 
log(date, ​"message1"​)
 
log(date, ​"message2"​) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required