Cover of Foundations of Professional Scala by Henri Cook

Foundations of Professional Scala

Scala gets written in two broad styles, as a more concise Java and as a functional language, and most books stick to one of them. This one starts in the first style and works its way to the second. Nearly every page has something to type and run, and the explanation comes after you’ve seen what the code does.

Start reading Also as ePub, mobi and PDF, or one chapter at a time. Download the code for every chapter.

A Scala 3 book for working Java developers. One project runs through it: Fully Booked, a table-booking system for a single restaurant. It starts in chapter 1 as a script, and by chapter 22 it’s an HTTP service with a Postgres database, a set of tests and a Docker image.

What’s in the book

Part I: Scala for Java developers

These chapters stay close to Java and cover values, case classes, collections, Option and testing.

  1. 1. Up and running
  2. 2. Values, methods and expressions
  3. 3. Case classes, enums and traits
  4. 4. Collections
  5. 5. Option, and life without null
  6. 6. Testing with MUnit

Part II: Getting the compiler to do the work

This part adds functions as values, types that model the problem and errors as ordinary values, then generics and givens.

  1. 7. Functions as values
  2. 8. Modelling with types
  3. 9. Errors as values
  4. 10. Generics and variance
  5. 11. Givens and type classes

Part III: Effects

Programs that do input and output and run concurrently, written with Cats Effect and fs2. The last chapter does the same work in direct style.

  1. 12. Build your own IO
  2. 13. Cats Effect
  3. 14. Concurrency
  4. 15. Failure, retries and timeouts
  5. 16. Streams with fs2
  6. 17. Direct style

Part IV: A real service

The project gets an sbt build, an HTTP API, a Postgres database, more tests and a Docker image. The last chapter is about Play.

  1. 18. From scala-cli to sbt
  2. 19. An HTTP API with Tapir and http4s
  3. 20. Postgres with doobie
  4. 21. Testing the service
  5. 22. Shipping it
  6. 23. Play: the Scala you’ll inherit

Appendices

Short guides to Scala 2 code and to the libraries the book doesn’t use.

The full contents

Questions and answers

Is the book free?

Yes. You can read the whole book on this site or download it in ePub, mobi or PDF format. The code for every chapter is a download as well.

Who is it for?

Java developers who would like to start working in Scala. You should already be able to program and know your way around Java’s classes, lambdas, streams and build tools. You don’t need to have seen any Scala before, or know anything about functional programming yet.

Which versions of Scala and Java does it use?

Scala 3.9 on JDK 25. Chapters 1 to 17 use Scala CLI, which is the scala command, and Part IV builds the service with sbt 2.

Which libraries does it use?

Cats Effect and fs2 for effects and streams, Tapir on http4s for the HTTP API, circe for JSON, doobie and Flyway for Postgres, and MUnit, ScalaCheck and Testcontainers for tests. There’s a chapter on direct style with Ox and one on Play.

Does it cover Scala 2, ZIO or Spark?

Briefly. The code in the book is Scala 3. Appendix A shows how to read Scala 2, since a lot of existing code is written in it, and ZIO and Spark each get a section in appendix B.

About the author

Henri Cook

Henri Cook is a Staff Engineer in London who has been writing Scala for a living for more than a decade. More about the author