Book Image

Learn Scala Programming

By : Slava Schmidt
Book Image

Learn Scala Programming

By: Slava Schmidt

Overview of this book

The second version of Scala has undergone multiple changes to support features and library implementations. Scala 2.13, with its main focus on modularizing the standard library and simplifying collections, brings with it a host of updates. Learn Scala Programming addresses both technical and architectural changes to the redesigned standard library and collections, along with covering in-depth type systems and first-level support for functions. You will discover how to leverage implicits as a primary mechanism for building type classes and look at different ways to test Scala code. You will also learn about abstract building blocks used in functional programming, giving you sufficient understanding to pick and use any existing functional programming library out there. In the concluding chapters, you will explore reactive programming by covering the Akka framework and reactive streams. By the end of this book, you will have built microservices and learned to implement them with the Scala and Lagom framework.
Table of Contents (19 chapters)

Writer monad

The Writer monad is a sibling of the state and the reader, oriented on modifying the state. Its main purpose is to provide a facility to write into some kind of log by passing this log between computations. The type of the log is not specified, but usually, some structure with a possibly low overhead of the append operation is chosen. To name a few suitable possibilities, you could use a Vector from the standard library or a List. In the case of the List, we need to prepend the log entries and revert the resulting log at the very end.

Before we get too deep into the discussion about the type of log, it is good to realize that we can defer the decision until later. All we need to know is how to append an entry to the existing log. Or, in other words, how to combine two logs, one of which contains just a single entry, together. We already know about the structure with...