front matter
Functional Programming in Scala is an intriguing title. After all, Scala is generally called a functional programming language, and there are dozens of books about Scala on the market. Are all these other books missing the functional aspects of the language? To answer the question, it’s instructive to dig a bit deeper. What is functional programming? For me, it’s simply an alias for programming with functions─that is, a programming style that puts the focus on the functions in a program. What are functions? Here we find a larger spectrum of definitions. While one definition often admits functions that may have side effects in addition to returning a result, pure functional programming restricts functions to be as they are in mathematics: binary relations that map arguments to results.
Scala is an impure functional programming language in that it admits impure as well as pure functions and in that it does not try to distinguish between these categories by using different syntax or giving them different types. It shares this property with most other functional languages. It would be nice if we could distinguish between pure and impure functions in Scala, but I believe we have not yet found a way to do so that is lightweight and flexible enough to be added to Scala without hesitation.