Book Image

Scala Design Patterns

By : Ivan Nikolov
Book Image

Scala Design Patterns

By: Ivan Nikolov

Overview of this book

Scala has become increasingly popular in many different IT sectors. The language is exceptionally feature-rich which helps developers write less code and get faster results. Design patterns make developer’s lives easier by helping them write great software that is easy to maintain, runs efficiently and is valuable to the company or people concerned. You will learn about the various features of Scala and be able to apply well-known, industry-proven design patterns in your work. The book starts off by focusing on some of the most interesting features of Scala while using practical real-world examples. We will also cover the popular "Gang of Four" design patterns and show you how to incorporate functional patterns effectively. By the end of this book, you will have enough knowledge and understanding to quickly assess problems and come up with elegant solutions.
Table of Contents (20 chapters)
Scala Design Patterns
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Partial functions


In mathematics, and as a consequence in programming, there are functions that are not defined for all possible inputs. A simple example will be the square root function—it will only work for real numbers if they are non-negative. In this section, we will look at partial functions and how we can use them.

Partial functions are not partially applied functions

There seems to be some confusion around what partial functions are and what they are not. It is important for you to understand that these functions are not partially applied functions. Partially applied functions are simply functions that might take multiple parameters and we've specified some of them and then they return functions with fewer parameters that we can specify. There is another term—curried functions—that is related to partially applied functions. In terms of functionality, they provide the same functionality. Let's see a quick example:

/**
 * Note that these are not partially defined functions!
 */
object...