This is a two day course. You are expected to know how to program in at least one programming language (Java, Ruby, JavaScript, etc.). The course teaches the fundamentals of using Scala as a functional programming language.
This course is meant to be run in person. There are comments in the exercises to try and point you in the right direction so you should be able to do this in your spare time if you desire. Unit tests are included to verify your solutions for each exercise.
Use sbt test
to run the tests. The first time you run the tests, they will all fail. This is a good thing! As you complete each exercise correctly, the tests will pass.
We welcome pull requests and feedback!
- 9.30 - Start
- 10 - Intro to FP/Scala (presentation)
- 10.30 - IntroExercises
- 11 - Break
- 11.15 - Intro to ADTs (presentation)
- 11.30 - TypesExercises
- 12.15 - Lunch
- 1:30 - ListExercises
- 3 - Break
- 3.15 - NullExercises (skip if familiar with downside of nulls)
- 3.45 - OptionExercises pt. 1 (Safe constructors)
- 4:45 - End
- 9.30 - Intro to Error Handling (presentation)
- 10.15 - OptionExercises pt. 2
- 11.15 - Break
- 11.30 - ExceptionExercises (skip if familiar with downside of exceptions)
- 12.30 - Lunch
- 1.30 - Exceptions2EitherExercises / EitherExercises (Optional)
- 2 - Break
- 2.15 - TryExercises
- 3.15 - LogParser
- 4.15 - End
1. Fork or clone this repository
git clone https://github.com/wjlow/intro-to-scala.git
cd intro-to-scala/
2. Install Java 8 (do not install Java 9 or Java 10)
brew tap caskroom/versions
brew cask install java8
3. Install sbt 1.x (recommended but optional, we have included a portable version)
We recommend that you install sbt
on your machine even though a portable runner is included.
The actual version of
sbt
used is in yourproject/build.properties
file and the globalsbt
is merely used for bootstrapping your project. You should not get conflictingsbt
installations even if you have multiple Scala projects using different versions ofsbt
.
brew install sbt@1
Tip: Launching SBT might take some time, so we recommend using SBT's interactive shell to run commands, instead of lauching SBT for each command.
To run the sbt
shell from the global installation use:
sbt
To run the sbt
shell from the portable installation use:
./sbt
4. Compile program to resolve dependencies before the course
Launch the SBT shell.
To only compile production code use:
~compile
To compile production and test code use:
~test:compile
To run all tests use:
test
The first time you run all the tests you will get a lot of errors! These tests will be fixed by you during the duration of the course.
In the meantime, run only a single test case at a time to keep things manageable.
To run a single test use:
~testOnly package.path.of.test.TestName
For example to run only the fundamentals.level01.IntroExercisesTest test case use:
~testOnly fundamentals.level01.IntroExercisesTest
To run by test case name only use:
~testOnly *TestName
For example to run the fundamentals.level01.IntroExercisesTest test case use:
~testOnly *IntroExercisesTest
The ~
watches for changes to your files and runs the command automatically. It's nice to use it to get really fast feedback as you are working on the exercises!
To stop watching changes through ~
, use the enter key to return to the SBT shell prompt.
To launch into a Scala REPL with all production code use:
console
To launch into a Scala REPL with all production and test code use:
test:console
Type :q
to exit from the REPL and return to SBT.
To exit the SBT shell use:
exit
IntelliJ IDEA
-
Install and open IntelliJ
-
If running IntelliJ for the very first time, it might ask you what plugin you want to install. Select Scala, otherwise install manually: Configure -> Plugins -> Browse Repositories -> Scala
-
Restart IntelliJ to activate the plugin
-
Open IntelliJ and open this project: Open -> Select directory where project is in
-
Wait for IntelliJ to download dependencies (this might take a while)
-
Compile project with Command+F9
-
You can run individual tests by right-clicking and then selecting Run ...ExercisesTest (or just use SBT)
Tips:
-
Use Command+P inside the argument of a function to see what type the argument needs to be.
-
Use Control+Shift+P to find out the type of a highlighted expression.
Text Editor (Vim/Sublime/Atom/Emacs)
-
Open the current directory in an editor of your choice.
-
Open the SBT shell in a terminal window.
-
Compiling - See SBT instructions on how to compile code.
-
Running Tests - See SBT instructions on how to run tests.
-
Looking up Scala API - You can also search through the Scala APIs to find any necessary methods or use a documentation browser like Dash.
-
To explore the Scala API or any of the exercises use the Scala REPL See SBT instructions on how to jump into the REPL.