---
# 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: String
)
def retrieveAddress: Option[Address] = {
    // TODO: Implement
    for {
        str1 <- Try(getStreet1).toOption
    } yield {
        Address(str1, Try(getStreet2).toOption, Try(getStreet3).toOption)
    }
}

sealed trait Error
case object NoStreet1 extends Error
case object NoStreet2 extends Error
case object NoStreet3 extends Error

def retrieveAddress: Either[List[Error], Address] = {
    // TODO: Implement
    for {
        str1 <- Try(getStreet1).toOption
    } yield {
        Address(str1, Try(getStreet2).toOption, Try(getStreet3).toOption)
    }
}


val x = retrieveAddress // Left(List(NoStreet1, NoStreet1))

// =======================================================================  
// 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
}