【发布时间】:2020-05-27 09:21:45
【问题描述】:
我有这样的功能:
def foo(item: Item) : Option[Int] = Try{
// Some code that can blow up
}.toOption
我有一个项目列表,我想通过它们进行映射,并应用上述功能。但是如果上面的函数爆炸并返回一个 None 那么映射的结果应该是一个错误:
items.map{
item => foo(item)
}
在这里做地图不合适吗?好像没有
【问题讨论】: