Scala Option object inside another Option object
I have a model, which has some Option fields, which contain another Option fields. For example: case class First(second: Option[Second], name: Option[String]) case class Second(third: Option[Third], title: Option[String]) case class Third(numberOfSmth: Option[Int]) I'm receiving this data from external JSON's and sometimes this data may contain null's, that was the reason of such model design. So the question is: what is the best way to get a deepest field? First.get.second.get.third.get.numberOfSmth.get Above method looks really ugly and it may cause exception if one of the objects will be