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

The Scalaz library


Scala is a functional programming language and as such it supports design patterns based on concepts such as monoids, monads, and others. We already saw these in Chapter 10, Functional Design Patterns – The Deep Theory, and we know the rules they follow and the structure they have. We wrote everything ourselves, but a library already exists that does this for us—Scalaz (https://github.com/scalaz/scalaz). This library is used when we need purely functional data structures.

We have already encountered Scalaz in the previous chapter when we talked about lenses. In the following subsections, we will look at the library from the point of view of monoids, functors, and monads.

Monoids in Scalaz

One of the concepts we looked at in Chapter 10, Functional Design Patterns – The Deep Theory was monoids. We defined a trait and some rules for them and then showed examples of how to use them and what they are good for. In these examples, we defined monoids for integer addition and multiplication...