Need help with fpinscala?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

5.3K Stars 2.9K Forks MIT License 393 Commits 115 Opened issues


Code, exercises, answers, and hints to go along with the book "Functional Programming in Scala"

Services available


Need anything else?

Contributors list

Join the chat at

This repository contains exercises, hints, and answers for the book Functional Programming in Scala. Along with the book itself, it's the closest you'll get to having your own private functional programming tutor without actually having one.

There are two main branches in this repository: - first-edition - second-edition

Be sure to select the branch which matches the edition of the book you are reading!

Here's how to use this repository:

Each chapter in the book develops a fully working library of functions and data types, built up through a series of exercises and example code given in the book text. The shell of this working library and exercise stubs live in

, where
 is a package name that corresponds to the
chapter title (see below). When you begin working on a chapter, we
recommend you open the exercise file(s) for that chapter, and when you
encounter exercises, implement them in the exercises file and make sure
they work.

If you get stuck on an exercise, let's say exercise 4 in the chapter, you can find hints in

(if no hints are available for a problem, the file will just have a single '-' as its contents) and the answer along with an explanation of the answer and any variations in
. The finished Scala modules, with all answers for each chapter live in
. Please feel free to submit pull requests for alternate answers, improved hints, and so on, so we can make this repo the very best resource for people working through the book.

Chapter descriptions:

  • Chapter 2: gettingstarted
  • Chapter 3: datastructures
  • Chapter 4: errorhandling
  • Chapter 5: laziness
  • Chapter 6: state
  • Chapter 7: parallelism
  • Chapter 8: testing
  • Chapter 9: parsing
  • Chapter 10: monoids
  • Chapter 11: monads
  • Chapter 12: applicative
  • Chapter 13: iomonad
  • Chapter 14: localeffects
  • Chapter 15: streamingio

Setup build environment

You'll need a Java development kit installed as well as the SBT build tool. If you don't have these tools, we can get them via Couriser. First, install Coursier by choosing an installation method for your operating system on this page: Then run

cs setup
. This will install Java, Scala, and the SBT build tool.

You'll also likely want an editor that's aware of Scala syntax. VSCode with the Metals extension works great.


To build the code for the first time, if on windows:

$ sbt.cmd

If on mac/linux, first make sure you have not checked out the code onto an encrypted file system, otherwise you will get compile errors regarding too long file names (one solution is to put the fpinscala repo on a unencrypted usb key, and symlink it into your preferred code location).

$ sbt

Once it is finished launching, you'll get a prompt from which you can issue commands to build and interact with your code. Try the following:

> project exercises
> compile

This switches to the exercises project, where your code lives, and compiles the code. You can also do:

> console

to get a Scala REPL with access to your exercises, and

> run

To get a menu of possible main methods to execute.

All code in this repository is MIT-licensed. See the LICENSE file for details.

Have fun, and good luck! Also be sure to check out the community wiki for the chapter notes, links to more reading, and more.

Paul, Rúnar, and Michael

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.