September 2019
Intermediate to advanced
462 pages
11h 3m
English
Functional programmers talk about lambdas and closures. Many programmers use those two terms interchangeably, which is acceptable, as long as we know the difference and can discern which one we’re using based on the context. Let’s take a closer look at how lambdas bind to variables and how that relates to the concept of closures.
A lambda is stateless; the output depends on the values of the input parameters. For example, the output of the following lambda is twice the value of the given parameter:
| | val doubleIt = { e: Int -> e * 2 } |
Sometimes we want to depend on external state. Such a lambda is called a closure—that’s because it closes over the defining scope to bind to the properties and ...
Read now
Unlock full access