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)

Questions

  1. Implement Monad[Try].
  2. Prove the right identity law for the State monad.
  3. Pick one of the monads we defined in this chapter and implement the go function, which will encode the notion of sinking the boat with a probability of 1%.
  4. Please do the same as question 3, but encode the notion of motor breaking in 1% of the moves, leaving the boat immobilized.
  5. Describe the essence of the monads we defined in this chapter by using the (loosely) following template—The state monad passes state between chained computations. The computation itself accepts the outcome of the previous calculation and returns the result, along with the new state.
  1. Define a go method that both tracks the position of the boat and takes the possibility of sinking the boat by using the structure with the following type:
type WriterOption[B] = Writer[Vector[(Double, Double)], Option[Boat]]
  1. Compare...