---
# System prepended metadata

title: Question

---

# Question

Implement the function `retrieveAddress` using the methods `getStreet1`, `getStreet2`, and `getStreet3` to create an `Address`.

```scala
  import scala.util.Try
  import scala.util.Success
  import scala.util.Failure
  case class Address(street1: String, street2: Option[String], street3: Option[String])

  // getStreet1 succeeds  
  // getStreet2 fails
  // getStreet3 fails


  // TODO: Implement
  def retrieveAddress: Option[Address] = {
  
      //Address("Address", "address", exception)
      //Address("Address", exception, "address")
      //Address("Address", exception, exception)
      Address(getStreet1, Some(getStreet2), Some(getStreet3))
  }
  
  def retrieveAddress: Address = {
      val street2 = Try(getStreet2).toOption
      val street3 = Try(getStreet3).toOption
      Address(getStreet1, street2, street3)    
  }

  
  def foo(t: Try[String]): Option[String]
  
  Try(getStreet1) match {
   case Success(street1) =>
                   Try(getStreet2) match {
                       case Success(street2) =>
                           val street3_1 =  Try(getStreet3).toOption
                       case Failure(ex) => 
                           Some(Address(street1,None, street3_1))
                       }
   case Failure(ex) => None
   }
  
   
  
  
  }
  
  case class Result(a: Address, errors: List[String])

  /**
    * Retrieves the main street address.
    *
    * @throws RuntimeException
    */
  def getStreet1: String = {
    // implementation
  }

  /**
    * Retrieves additional street address line 2.
    *
    * @throws RuntimeException
    */
  def getStreet2: String = {
    // implementation
  }

  /**
    * Retrieves additional street address line 3.
    *
    * @throws RuntimeException
    */
  def getStreet3: String = {
    // implementation
  }

```

