September 2015
Intermediate to advanced
250 pages
6h 40m
English
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") ... |
Read now
Unlock full access