I have an Option instance, say O, which contains an instance of a class, say A, and A itself has some Options inside it.
I have to achieve something like this, expressed in pseudo code as:
if(A.x exists) {
if(A.y exists) {
//extract values from some another Option Z embedded in A
} else {
// return Option of some default value
}
}
So I try this:
O.filter(some filter condition to have only some specific types of A).filter(!A.x.isEmpty).filter(!A.y.isEmpty).flatMap(_.z.somevalue).orElse(Some("Some default value"))
Is this the correct way, OR do I need to use pattern matching at some point?
Edit: Result should be an Option[String].O si an Option[A]. A is a class with fields x,y,z, and all three are Option of String.