【发布时间】:2020-07-04 15:29:17
【问题描述】:
我有一段代码,我在其中使用了模式匹配,我在所有情况下都使用了 map,我想得到 map 给变量的输出。以下是我的代码:
override def run():List[Option[Student]] =
StudentDataCache.get(surname) match {
case Some(i) => i.otherSiblings.map(siblings =>
StudentDataCache.get(siblings) match {
case Some(i) => Some(i)
case None=> getStudentFromDatabase(siblings)
}
)
case None =>
getStudentFromDatabase(surname).get.otherSiblings.map(siblings => StudentDataCache.get(siblings) match {
case Some(i) => Some(i)
case None=> getStudentFromDatabase(siblings)
}
)
}
case 内的 map 语句的输出都是 List[Option[Student]],有没有办法将它转换为变量,因为我想将此列表转换为单个对象,因为 HystrixCommand 执行输出不支持 List 作为输出.我想将其转换为 StudentListing(val listing: List[Option[Student]])
【问题讨论】:
标签: scala