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. sbt
is going to do all the heavy lifting though, so
hopefully it is all straight forward, if not, send
us an email via mark@hibberd.id.au.
Pre-requisites.
- A valid install of java 6+
- git
- 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.
If you want to run all the tests once then you can simple run
./sbt test
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*
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
in project/plugins.sbt
that will help you get started:
You can generate project files for eclipse with (after uncommenting sbteclipse-plugin plugin):
./sbt eclipse
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. ;-)
- Lists - src/main/scala/intro/List.scala
- Errors without exceptions - src/main/scala/intro/Result.scala
NOTE: Applicative
can often prove more tricky than Monad
, feel free to flip the order if you get stuck.
- src/main/scala/intro/Functor.scala
- src/main/scala/intro/Applicative.scala
- src/main/scala/intro/Monad.scala
If you enjoyed parsing and want some more then writing a json parser is also fun:
- src/main/scala/patterns/Reader.scala
- src/main/scala/patterns/Writer.scala
- src/main/scala/patterns/State.scala
- src/main/scala/patterns/Http.scala
- src/main/scala/patterns/ReaderT.scala
- src/main/scala/patterns/WriterT.scala
- src/main/scala/patterns/StateT.scala
- src/main/scala/patterns/MonadTrans.scala
- src/main/scala/patterns/HttpT.scala