Hello lanig.
Just to complete comments, Scala’s Option[Type] is very idiomatic and it’s everywhere. You’ll get used to it very soon.
Taking your example, It is declared with Option[Boolean]. It is used with Some(true) or Some(false).
The usual case when you might find it useful is to report a value or the absense of it.
A good example is querying a Hash (Map) whether a value is present or not:
groupOfCards.get (certainCard) match {
case Some (card) => /* do something with with card */
case None => /* no card was found */
}
In your particular case, it is not interesting to use Option[Boolean] because you know that the color will match or not, but in any case you will have a value (Boolean). true or false.
In essense, there’s no absence, so Option[Boolean] helps nothing here.
Putting in practise this, a valid, though not optimal way of implementing your example will be (let me reword your example to english for more people to understand):
// working example, but not recommended
def sameColour (c1 : Card, c2 : Card) : Option[Boolean] = Some (c1.c == c2.c)
Why it is not recommended? As we have said, it is not recommended because you always have a value, so returning always Some(true) or Some(false) will only add burden to the API consumer, plus, you can resolve the problem directly:
// working recommend example
def sameColour (c1 : Card, c2 : Card) : Boolean = {
c1.c == c2.c
}
…and, even shorter, using Scala type system:
// let Scala infer types
def sameColour (c1 : Card, c2 : Card) = c1.c == c2.c