We have the following case classes in our service domain:
case class Owner(name: String, phone: String)
case class Car(name: String, isCrashed: Boolean, owner: Maybe[Owner])
We need a function that will retrieve the owner's phone number if the car data has been presented and the car has not been broken. We have written it, but our specific data type Maybe must have several methods implemented to make this code work:
def getOwnerPhone(maybeCar: Maybe[Car]): Maybe[String] =
for
car <- maybeCar if !car.isCrashed
owner <- car.owner
yield owner.phone
Complete the Maybe data structure.