What should be used instead of someMethod in the following code to get correct results?
case class Employee(
name: String,
department: String,
manager: Option[String]
)
def lookupByName(name: String): Option[Employee] = name match {
case "Joe" => Some(Employee("Joe", "Finances", Some("Julie")))
case "Mary" => Some(Employee("Mary", "IT", None))
case "Izumi" => Some(Employee("Izumi", "IT", Some("Mary")))
case _ => None
}
def getManager(employee: Option[Employee]): Option[String] = employee.flatMap(_.manager)
getManager(lookupByName("Joe")).someMethod(Some("Mr. CEO")) == Some("Julie")
getManager(lookupByName("Mary")).someMethod(Some("Mr. CEO")) == Some("Mr. CEO")
getManager(lookupByName("Foo")).someMethod(Some("Mr. CEO")) == Some("Mr. CEO")
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати