---
# 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]
)



def retrieveAddress: Try[Address] = {
    // TODO: Implement
    def trystreet1: Try[String] = Try(getStreet1).toOption
    def trystreet2: Try[String] = Try(getStreet2)
    def trystreet3: Try[String] = Try(getStreet3)
    
    List(1,2,3).map(i: Int => i * 2)  // List(2,4,6)
    List().map(i => i * 2)       // List()
    val x: Option[Int] = None
    val y: Option[Int] = Some(10)
    y.map(i: Int => (i * 2): Int) // Some(20)
    x.map(_ * 2) // None
    
    val a: Try[Int] = Failure(new Throwable("BOOM"))
    val b: Try[Int] = Success(5)
    b.map(i => i * 2) // Success(10)
    a.map(i => i * 2) // Failure(...)

    trystreet1.map(s => Address(s, trystreet2.toOption, trystreet3.toOption)
}


// =======================================================================  
// JAVA LIBRARY METHODS 
// =======================================================================
/**
  * Retrieves the main street address.
  * @throws Exception if empty
  */
def getStreet1: String
/**
  * Retrieves additional street address line 2.
  * @throws RuntimeException if empty
  */
def getStreet2: String
/**
  * Retrieves additional street address line 3.
  * @throws RuntimeException if empty
  */
def getStreet3: String