scala-for-the-impatient
scala-for-the-impatient copied to clipboard
My answers to the exercises from the book "Scala for the impatient" (2nd edition) -- 2017.
Scala for the impatient
I discovered scala during a Master course and was immediately seduced by it. There are many things I love about it: its support for both funtional and OO programming (immutable collections are the default!), the number of different ways to do one thing, the type inference system, the currying and lambda support, the partially applied function syntax, … In short, I like it.
To better understand the language (one course is a bit limited to grasp the whole power of scala), I began reading "Scala for the impatient" by Cay Horstmann.
This repository contains my solution to Horstmann's book. They are far from perfect (given that I just discovered scala and never really used it outside of this repo), but it was very fun to do.
==> https://derlin.github.io/scala-for-the-impatient <==
Notes about the sources
I used Intellij Idea along with the scala plugin, with scala 2.12. I did many exercises in a scala worksheet, which I found easier for quick testing. If you try to run a worksheet and run into trouble, simply copy-paste the part of the code you want to test into a regular scala file:
object MyApp extends App {
// put the code here
// don't forget to use println() to output the results
// to the console
}
gh-pages
docco
To generate the html in gh-pages, I used docco with the parallel template with slight changes. You can find the template in the docco-template directory. To regenerate the HTML files, use:
docco -t docco-template/docco.jst -c docco-template/docco.css -o gh-pages src/main/scala/* index.md
Important: the .sc extension is not recognized by docco. Unfortunately, the -e .scala option of the docco command-line tool cannot be used, since we also have a .md in the source list (for the jump to section to be correct, we need all the sources to be processed at the same time). Quick fix: find the node_modules/docco directory, open the languages.json file in your favorite editor and add the following to the list:
".sc": {"name": "scala", "symbol": "//"},
git setup
To manage themaster and the gh-pages branches, I followed the tips presented in this gist. In short:
-
create a repo with your sources
-
add the name of the folder which will contain the sources of the gh-pages branch to the
.gitignore -
commit and push to
origin master -
navigate to the child folder (the one for the gh-pages, let's call it
gh-pages) and- clone your repo
- create a
gh-pagesbranch - remove the
masterbranch (don't worry, won't affect the remote) - remove all the files from the master that you don't need in your gh-pages, add files as you need
- commit and push to
origin gh-pages
git clone <your repo origin> git checkout -b gh-pages git branch -d master rm <everything but the .git folder> git commit -a "first child commit" git push origin gh-pages