This is the base project for the workshop.
note: please test your environment before you arrive so we can get started quickly on the day.
Before you attend you will need to get a few things
ready and ensure everything is setup properly.
is going to do all the heavy lifting though, so
hopefully it is all straight forward, if not, send
us an email via firstname.lastname@example.org.
- A valid install of java 6+
- if you are windows only install sbt using the msi installer
Getting scala and validating your environment:
git clone https://github.com/markhibberd/introduction-to-fp-in-scala.git cd introduction-to-fp-in-scala ./sbt "test:compile" # For windows users just use your installed `sbt` directly without the `./`
For either platform this may take a few minutes. It will:
- Download the sbt build tool.
- Download the required versions of scala.
- Compile the main and test source code.
You should see no errors and an exit code of 0.
Running the tests
If you want to run all the tests once then you can simple run
However this can be tedious, and requires waiting for SBT to start and for all the tests to run (which might get noisy if they fail). It is recommend to start the SBT console and run specific tests in a loop, which is handy when working on a particular exercise:
# Start the SBT terminal once, and then subsequent commands are run within that program # Be careful not to type Ctrl^C as this kills the entire session ./sbt # Run the tests from a package containing the name "Id" > testOnly *Id* # Add a ~ for starting a watch daemon to recompile and re-run tests when files are changed > ~testOnly *Result*
Working with scala.
Any good text editor will be sufficient for the course. If you
prefer an IDE, you can use the eclipse based scala-ide,
intellij, or emacs with ensime. There are commented out lines
project/plugins.sbt that will help you get started:
You can generate project files for eclipse with (after uncommenting sbteclipse-plugin plugin):
If you want to use ensime (after uncommenting ensime-sbt-cmd):
./sbt 'ensime generate'
You can import the project files for intellij if you have the latest scala plugin enabled.
Just note that if you choose eclipse or intellij, have a backup texteditor as well, because there won't be enough time to debug any editor issues.
There is about two weeks worth of material available, people with different backgrounds will progress through at different rates.
If get get stuck there is an answers folder where you can look for help or inspiration. Don't feel bad if you need to peek. ;-)
Just enough scala
What is functional programming?
Introduction to data structures and higher order functions
- Lists - src/main/scala/intro/List.scala
- Errors without exceptions - src/main/scala/intro/Result.scala
Intro to Type Classes
Applicative can often prove more tricky than
Monad, feel free to flip the order if you get stuck.
Algebra for fun and profit
If you enjoyed parsing and want some more then writing a json parser is also fun:
Patterns in Types