---
# 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: String,
  street3: Option[String]
)

sealed trait FailingStreet

case class Street1(errorMessage: String) extends FailingStreet
case class Street2(errorMessage: String) extends FailingStreet

Option[Either[String,Int]]

def retrieveAddress: Either[(FailingStreet, String), Address] = {
    // TODO: Implement
    // I can edit it
    (for {
        street1 <-     Try(getStreet1) match {
        case Failure(t) => Left((Street1, t.getMessage)
        case Success(r) => Right(r)
    } //Either[Throwable,Address]

        street2 <-     Try(getStreet2) match {
        case Failure(t) => Left(Street2, t.getMessage)
        case Success => Right(r)
    } //Either[Throwable,Address]

    } yield Address(street1, street2, Try(getStreet3).toOption))    
}

val res = retrieveAddress
res match {
    case Left(Street1) => 
    case Left(Street2) => 
    case Right(a) =>
      
}
// =======================================================================  
// 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
}