336062 (2) [Avatar] Offline

I was wondering why all the methods in errorhandling section were defined in the trait instead of in the actual case classes?

sealed trait Option[+A] {
  def map[B](f: A => B): Option[B] = this match {
    case None => None
    case Some(a) => Some(f(a))
// ...

Is this the proper functional way?

runar (53) [Avatar] Offline
It is just easier to see, since then the definition of these functions are not scattered among the case classes. Either way works in this particular case.

But beware when you start to make recursive definitions. A recursive definition on cases in the trait can be tail-recursive, but mutually recursive definitions in the case classes cannot.
336062 (2) [Avatar] Offline
Yeah, later I found out that it's the design decision between functional or oo.

Thanks for your answer,