---
# System prepended metadata

title: Question

---

# Question
Implement the function `retrieveAddress` using the methods `getStreet1`, `getStreet2`, and `getStreet3` to create an `Address`.
```scala
case class Address(
  street1: String,
  street2: Option[String],
  street3: Option[String]
)

case class StreetFailed(error: Throwable)
def retrieveAddress: Either[Throwable, Address] = {
    // TODO: Implement
    
    val addreess: Try[Address] = for {
        street1 <- Try(getStreet1)
        street2 = Try(getStreet2).toOption
        street2Modified = street2 match {
            case Failure(_) => None
            case Success(str2) => Some(str2)
        }
        street3 <- Try(getStreet3)
    } yield Address(street1, street2Modified, Option(street3))
    

    Try(getStreet1).map{ street1 => 
        Address(street1, Option(getStreet2), Option(getStreet3) )
    }
    
}
// =======================================================================  
// LIBRARY METHODS 
// =======================================================================
/**
  * Retrieves the main street address.
  * @throws RuntimeException if empty
  */
def getStreet1: String = {
  // implementation
}
/**
  * Retrieves additional street address line 2.
  * @throws RuntimeException if empty
  */
def getStreet2: String = {
  // implementation
}
/**
  * Retrieves additional street address line 3.
  * @throws RuntimeException if empty
  */
def getStreet3: String = {
  // implementation
}