Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fpinscala/fpinscala
Code, exercises, answers, and hints to go along with the book "Functional Programming in Scala"
https://github.com/fpinscala/fpinscala
Last synced: 3 days ago
JSON representation
Code, exercises, answers, and hints to go along with the book "Functional Programming in Scala"
- Host: GitHub
- URL: https://github.com/fpinscala/fpinscala
- Owner: fpinscala
- License: mit
- Created: 2012-02-23T15:26:37.000Z (almost 13 years ago)
- Default Branch: second-edition
- Last Pushed: 2024-09-03T21:03:49.000Z (3 months ago)
- Last Synced: 2024-12-02T22:02:26.258Z (10 days ago)
- Language: Scala
- Homepage: http://manning.com/bjarnason
- Size: 5.48 MB
- Stars: 5,703
- Watchers: 314
- Forks: 3,047
- Open Issues: 137
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - fpinscala - Code, exercises, answers, and hints to go along with the book "Functional Programming in Scala" (Scala)
- awesome-list - fpinscala
README
[![Join the chat at https://gitter.im/fpinscala/fpinscala](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/fpinscala/fpinscala?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This repository contains exercises, hints, and answers for the book
[Functional Programming in Scala](http://manning.com/bjarnason/). 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](https://github.com/fpinscala/fpinscala/tree/first-edition)
- [second-edition](https://github.com/fpinscala/fpinscala/tree/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
`src/main/scala/fpinscala/exercises/`, 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 `answerkey//04.hint.md` (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
`answerkey//04.answer.md`. The finished Scala
modules, with all answers for each chapter live in
`src/main/scala/fpinscala/answers/`. 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
The project is setup to use [Scala CLI](https://scala-cli.virtuslab.org). First install Scala CLI by following the [installation instructions](https://scala-cli.virtuslab.org/install).
You'll also likely want an editor that's aware of Scala syntax. [VSCode](https://code.visualstudio.com) with the [Metals](https://scalameta.org/metals/docs/editors/vscode.html) extension works great.
### Building
To build the code for the first time, from the root directory of the project (i.e., the directory where this README.md is located):
$ scala-cli compile .
This compiles all exercises and answers. You can also do:
$ scala-cli console .
to get a Scala REPL (prompt `scala>`) with access to exercises and answers, and then for example:
scala> import fpinscala.exercises.datastructures.List
to import the `List` data type.
To run the sample programs:
$ scala-cli run .
This gives a list of possible main methods to execute. To run one of them:
$ scala-cli run . --main-class fpinscala.answers.gettingstarted.printAbs
To run a single unit-test, you can specify the fully qualified class name and test name:
$ scala-cli test . -- 'fpinscala.exercises.gettingstarted.GettingStartedSuite.MyProgram.factorial'
To run unit-tests for a package you can do:
$ scala-cli test . -- 'fpinscala.exercises.gettingstarted.*'
To run all unit-tests:
$ scala-cli test .
Note, running all tests will result in failures. As you solve exercises, the tests
will start to pass.### SBT
Note: an [SBT](https://www.scala-sbt.org) build is also provided.
### License
All code in this repository is
[MIT-licensed](http://opensource.org/licenses/mit-license.php). See the
LICENSE file for details.Have fun, and good luck! Also be sure to check out [the community
wiki](https://github.com/fpinscala/fpinscala/wiki) for the **chapter
notes**, links to more reading, and more._Paul, Rúnar, and Michael_