Aiming to combine object oriented and functional programming, Scala can be used (and abused) as another Java dialect without semicolon or as Haskell on JVM forgetting about its OOP feature. Finding a proper way of speaking the language, a balance between FP and OOP can be an interesting and long journey.

Depending on who you ask, you’ll probably get a different answer about the ‘proper way’.

In the end, there might be no proper way, there is only some way that fits your need at the moment.

I prefer just to enjoy the journey. Admiring coherence promised by the purist, and utilizing pragmatic modularity of the language. Learning, fiddling around and making notes along the way. In the course of this journey, I collected these exercises, talks highlights, and code snippets. Maybe they are useful for you also.

Exercises, snippets, and highlights are presented using ScalaFiddle so you can fiddle around without having to setup libraries needed.
If you have suggestions, corrections, ideas for exercises, feel free to create an issue or made a pull request.

Exercise Format

Exercises will be formatted using the following template :

  • A problem description, including source of exercise, where I found it on the net or in a book.
  • A learning ground to fiddle around with solution, there will be assertions to check correctness.
  • A solution, either from the book, or whatever I could come up with so far.

Example of exercise is as follows:

The two Numbers

This is an advance exercise to solve addition

Fiddle Around!


// Please solve this advanced exercise
def sum(a: Int, b: Int) = ??? 

import scala.util._ 

Try(sum(2, 4)) == Success(6)

Solution


def sum(a: Int, b: Int) = a+b 

sum(2, 4) == 6