有人可以帮我将其转换为 flatMap 或用于理解吗?我知道如何处理嵌套选项的更琐碎场景。
case class Person(name: String, signficantOther: Option[String])
val nightclubPeoples : Option[Seq[Person]] = ???
def significantOthers(nightClubPeoples : Option[Seq[Person]]) : List[String] = {
nightclubPeoples match {
case Some(x) => x map { y : Person =>
y.significantOther match {
case Some(z) => z
case None => "No Signficant Other"
}
}.toList
case None => Nil
}
}